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 2005 Forums
 Transact-SQL (2005)
 select into a variable

Author  Topic 

jgn1013
Starting Member

24 Posts

Posted - 2009-07-28 : 12:46:27
Need some help please, try to convert a oracle sql statement but have never worked with Select Into from variable.

This is the oracle stored procedure sample, can i get some help in converting to ms sql. TIA


create procedure test
(
@userid varchar(8),
@flag varchar(10),
@pwd varchar(8)
)
AS
declare @count int
declare @pwd2 varchar(8)

select tablename.password into @pwd2
from tablename
where upper(userid) = upper(@userid)

end

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-28 : 13:06:08
select @pwd2 = tablename.password from tablename where ...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-28 : 13:09:09
Also, if you do not have case sensitive collation on your SQL server then you do not need to use the UPPER function. Just thought I'd mention it just in case...
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-28 : 13:30:21
hope userid is a unique index, otherwise you'll get a random id out of a result set



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-28 : 13:36:10
My given solution is as wrong or as right as the code in the opening post.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jgn1013
Starting Member

24 Posts

Posted - 2009-07-28 : 14:15:27
quote:
Originally posted by webfred

My given solution is as wrong or as right as the code in the opening post.


No, you're never too old to Yak'n'Roll if you're too young to die.



the query "select @var = tablename.pwd where userid = @userid" just assigns the variable @var the pwd correct? If so then why can't i get this to work?

oracle statement

select distinct(wa) into @var from tablename where id = @id

I tried doing it this was but I get an error

select @var = distinct wa from tablename where id = @id
______________________________________________________________
Is this the solution?
select @var = (select ditinct(wa) from tablename where id = @id)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-28 : 14:43:13
So if you can't get it to work then what is the problem?
Is there an error message?
Please show:
executed statement
error message

Thank you for helping to help you


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jgn1013
Starting Member

24 Posts

Posted - 2009-07-28 : 14:46:07
I think this is the correct select statement


select @var = (select ditinct(wa) from tablename where id = @id)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-28 : 14:50:43
Then try it and you will know...

Good luck!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -