Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to use "SELECT INTO"

Author  Topic 

Chen
Starting Member

4 Posts

Posted - 2005-07-18 : 23:51:44
Hi all,

I am using Oracle a lot. I want to assign a selection result into a local variable the same as "SELECT INTO".

Here is my code. It works fine, But I need assign this result into
SET @sqlStmt = 'SELECT COUNT(*) FROM ' + @targetTbl + ' WHERE test_3 = ' + @newValue;
EXEC (@sqlStmt);

Can anyone kindly help me? thank you,

Chen

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-07-19 : 00:34:37
Doing this is a little tricky:

DECLARE
@RecCount int,
@targetTbl varchar(50),
@newValue varchar(10),
@sqlStmt nvarchar(255)

SET @sqlStmt = 'SELECT @RecCount = COUNT(*) FROM ' + @targetTbl + ' WHERE test_3 = ' + @newValue;

EXECUTE sp_executesql @sqlStmt, N'@RecCount int OUTPUT', @RecCount OUTPUT;

SELECT @RecCount;
Go to Top of Page

Chen
Starting Member

4 Posts

Posted - 2005-07-19 : 07:03:22
Thank you so much! I have to say the sql server syntax is really weird to me. :)
Go to Top of Page
   

- Advertisement -