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)
 set select value to declared var

Author  Topic 

havey
Starting Member

16 Posts

Posted - 2008-02-23 : 20:23:41
Hi i'm having trouble this is simple task, any thoughts:

declare @id int

set @id = select w.[PNumber]
from [WTables].[dbo].[Demographics] w
where w.ENo = 3012

the goal is to set the pNumber value to the @id

Thanks

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-02-23 : 20:31:01

What is the problem? Are you getting more than 1 record?

You could do it like this:

Select Top 1 @ID = w.PNumber
FROM [WTables].dbo.[Demographics] w
Where w.ENo = 3012





Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

havey
Starting Member

16 Posts

Posted - 2008-02-23 : 20:35:52
i was getting Incorrect syntax near the keyword 'select'.

Your suggestion worked!, thank you very much.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-25 : 03:09:50
quote:
Originally posted by havey

Hi i'm having trouble this is simple task, any thoughts:

declare @id int

set @id = select w.[PNumber]
from [WTables].[dbo].[Demographics] w
where w.ENo = 3012

the goal is to set the pNumber value to the @id

Thanks


You should have use

declare @id int

set @id = (select w.[PNumber]
from [WTables].[dbo].[Demographics] w
where w.ENo = 3012)

provided query returns single value

Madhivanan

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

- Advertisement -