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
 General SQL Server Forums
 New to SQL Server Programming
 select into

Author  Topic 

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-15 : 13:15:39
I want to select a number into a varible, syntax failed . how to fix it ?

Thanks


declare @insertCount int
select COUNT(*) into @insertCount from mytable
if @insertCount = 1
...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-15 : 13:30:13
select @insertCount = COUNT(*) from mytable

Or:

set @insertcount = select COUNT(*) from mytable

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-15 : 13:35:03
With brackets round the subquery for the second one :).

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-15 : 13:45:48
Oops!

set @insertcount = (select COUNT(*) from mytable)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-15 : 13:58:47
thanks a lot
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-15 : 14:38:33


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -