SQL PRINT statement prints nothing

by user146601   Last Updated March 13, 2018 06:06 AM

I dont get any output for this simple print statemewnt. What am I missing?

DECLARE @team varchar(20)

BEGIN
   SELECT @team = TEAM
   FROM DISTRIB_LINE 
   PRINT 'value is' + @team
END


Answers 1


PRINT outputs a message, not a resultset. Try something like the following:

DECLARE @team varchar(20)
SELECT TOP 1 @team = TEAM
FROM DISTRIB_LINE 

SELECT @team AS Team

My example contains TOP because I have ensured that @team receives a single value in a more deterministic way (the most certain is using a ORDER BY clause and a WHERE that enforces a single record).

Alexei
Alexei
March 13, 2018 05:36 AM

Related Questions



How to point View to a dynamic database

Updated March 16, 2016 08:02 AM

update using SQL Store Procedure

Updated April 20, 2015 20:02 PM