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 statement in sqlserver2005

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-02-21 : 06:38:38
Hi All, how can I use select into(of oracle) statement in sqlserver

Hi Kirsten, I have started the new thread, plz help it is giving syntax error for select into


begin
DECLARE @MyRowCountFlag int

select a,b into v1,v2 from tab where ...
IF @@ROWCOUNT=0 SELECT @MyRowCountFlag=1

select x,y into v3,v4 from tab2 where..
IF @@ROWCOUNT=0 SELECT @MyRowCountFlag=2
exception -- as per my understanding this exception is raised when any of the above select fails to retrive data ( i mean no rec)
IF @MyRowCountFlag IS NOT NULL
BEGIN
when_no_data found then
v1= some value
v2= some value
END

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-02-21 : 07:31:09
Hi

do i need to use some thing like below,

select @a = count(*) from tab where 1=2
then the problem is what If I have two columns
as below
select a,b into v1,v2 from tab where ...
count(*) would have worked if there was only one column.

still this technique will increase the code..

Kirsten any comment...

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-22 : 00:02:28
Try

select @a = count(a) from tab where 1=2
select @b = count(b) from tab where 1=2

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-22 : 08:27:47
what all counts do you want to retrieve in single statement? can you show that with some sample data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -