Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning values to @variables

Status
Not open for further replies.

seekwall

Programmer
May 14, 2001
41
GB
I need to be able to assign either one of two values to a local variable in a stored proc depending on what is returned from a boolean type statement.

Basically if this statement returns true:

if exists
(
select sc.*
from syscolumns sc
inner join sysobjects so on sc.id = so.id
where upper(sc.name) = 'title'
and upper(so.name) = 'Master6'
)

I want to declare the variable as 'title'

otherwise I want to declare the variable as ' '


Is this possible?

 
[tt]declare @nCount int, @cTitle varchar(20)

select @nCount = count(sc.id)
from syscolumns sc
inner join sysobjects so on sc.id = so.id
where upper(sc.name) = 'title'
and upper(so.name) = 'Master6'

if @nCount > 0
set @cTitle = 'Title'
else set @cTitle = ''
[/tt]
Robert Bradley
Sr. DBA, some big company
cheap prints and oil paintings:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top