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
 Transact-SQL (2000)
 How can i read a value from a table

Author  Topic 

grizzlee
Starting Member

6 Posts

Posted - 2008-04-22 : 04:53:57
Hi
I hope my post is in the right place, because it is the first time i post here.I have a table with index and value for ex.I'd like to read the exact value in a variable.

something like :
SELECT @var="select val from mytable where index=234"

because i need to know the value of val in order to run or not other instructions

if @var =0 then do something
else do something else

the problem is that i tried all the possible ways and did not manage to come to a result


harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-22 : 05:09:29
[code]Select @var = val from mytable where index=234[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

grizzlee
Starting Member

6 Posts

Posted - 2008-04-22 : 05:15:54
ohh, it is so simple and it works :)
thanks a lot
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-22 : 05:30:02
or

set @var = (select val from mytable where index=234)

Provided the query returns a single value

Madhivanan

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

grizzlee
Starting Member

6 Posts

Posted - 2008-04-22 : 05:49:28
ok thanx,a lot guys, now i have another question and i said it it better to ask it here than to open a new post

How can i find a schema from a database when i only know the owner, and read the value in a variable.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-22 : 08:56:48
Find it in Information_schema.tables view

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-22 : 08:57:32
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=101479

Madhivanan

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

- Advertisement -