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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what does the "select @health as Health" do in this query pls - is a value stored anywhere

Status
Not open for further replies.

droodle

Technical User
Nov 10, 2005
75
AU
DECLARE @a integer
DECLARE @health integer

select @a = COUNT(*) from DB
where prid = 'com'
and (severity = 'minor'
or severity = 'major'
or severity = 'critical')

if @a = 0
BEGIN
SELECT @health = 100
END
if @a > 0
BEGIN
SELECT @health = 70
END

select @health as Health
 
It returns one column which is called "Health" with the appropriate value ie 70 or 100.

Code:
as Health
simply names the output column - it does not necessarily refer to a specific column in table. This sort of syntax is often used for calculated columns or to make the column name more presentable for a user. For example if a table column is called "FIRSTNAME" you could use
Code:
SELECT FIRSTNAME as [First Name]
to make it look friendlier.
 
and statement
SQL:
select @a = COUNT(*) from DB
where prid = 'com'
and (severity = 'minor'
or severity = 'major'
or severity = 'critical')

you can change to
SQL:
select @a = COUNT(*) from DB
where prid = 'com'
and severity in ('minor', 'major', 'critical')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top