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)
 stored procedures and sub queries

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-07 : 02:18:47
i am in a SP(=stored procedures) making a sub query like this :


begin trans
insert into (a,b,c,d,e)
values (2,3,5,(select c,d from table1 where id=3) )

commit

i recive that a subquery isnt possible only scalar expressions are allowed!
what can i do?
thnaks i nadvance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-07 : 02:21:33
subquery can only return on column not 2.
insert into (a,b,c,d,e)
select 2,3,4,c,d
from table1
where id = 3


----------------------------------
'KH'


Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-03-07 : 02:22:38
yes coz you specified values, so it's looking for unit values... not result of subquer, imagine how many there are if id=3 returns more than 1 row?

try this...

insert into (a,b,c,d,e)
select 2,3,5,c,d from table1 where id=3

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-07 : 03:16:30

That should be
insert into yourTable(a,b,c,d,e)
select 2,3,5,c,d
from table1
where id = 3



Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-07 : 03:39:49
. Thanks Madhivanan

----------------------------------
'KH'


Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-07 : 05:33:10
thnaks all of u

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page
   

- Advertisement -