[dba-SQLServer]Selecting data into variables

Billy Pang tuxedo_man at hotmail.com
Wed Oct 8 00:20:24 CDT 2003


Like this?

/* -- cut here */
USE NORTHWIND
DECLARE @prod_name varchar(50)
SELECT @prod_name = productname from products where productid = 4;
PRINT @prod_name
/* -- cut here */


Billy

>From: David Emerson <davide at dalyn.co.nz>
>Reply-To: dba-sqlserver at databaseadvisors.com
>To: dba-SQLServer at databaseadvisors.com
>Subject: [dba-SQLServer]Selecting data into variables
>Date: Wed, 08 Oct 2003 16:55:49 +1300
>
>I would like to run a select statement that returns 1 row, then put the 
>column values into variables I have declared in my Sproc.  The closest I 
>have come across in BOL is the SELECT INTO statement but this is for 
>"Embedded SQL for C and SQL Server".
>
>I could use a cursor but it seems overkill for only one row.  Is there an 
>easy way to do this?
>
>Regards
>
>David Emerson
>DALYN Software Ltd
>25b Cunliffe St, Johnsonville
>Wellington, New Zealand
>Ph/Fax (877) 456-1205
>
>_______________________________________________
>dba-SQLServer mailing list
>dba-SQLServer at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
>http://www.databaseadvisors.com
>

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online  
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963



More information about the dba-SQLServer mailing list