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
 Other Forums
 Other Topics
 DEFINE

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-12-15 : 07:56:56
JASON writes "Is it possible to loo =k upb a value in a table and use it as a define command?

e.g. define name =
(select a.name
from name
where order = 1)

select *
from surname
where a.name = &name;
commit;"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-15 : 08:01:48
[code]Declare @name varchar(8000)

select @name = a.name
from name a
where order = 1

select *
from surname a
where a.name = @name;[/code]

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-15 : 10:14:32

1 Make sure that the query returns single value
2 You can also use

select *
from surname a
where a.name in
(select name
from name a
where order = 1)

Madhivanan

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

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-12-15 : 11:03:22
Better still use a join

select S.*
from surname S
inner join name N on N.name = S.name
where N.order = 1
Go to Top of Page
   

- Advertisement -