problem with query | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

problem with query

I am trying to monitor the length of a particular column called responsibility for the table positiontitle SELECT DATALENGTH (Responsibility) AS ‘length2’, Responsibility
FROM Positiontitle
WHERE PosName = ‘planner2’
if (length2) > 1
exec master..xp_sendmail ‘[email protected]‘, ‘The Planner2 record length in responsibility table are less than 1’ when I execute its erroring out with this statement: Server: Msg 207, Level 16, State 3, Line 4
Invalid column name ‘length2’. when i just execute this SELECT DATALENGTH (Responsibility) AS ‘length2’, Responsibility
FROM Positiontitle
WHERE PosName = ‘planner2’ the output is
length2 Responsibility
3362<Root><DimensionName Name="Organization" levelsList=",0,"><set level="0" hierarchy="null" levelname="[Organization].[(All)]" pathToRoot="(All)">[Organization].[(All)].Members</set></DimensionName><DimensionName Name="Plan" levelsList=",1,"><set level="1" I want to check the first column length2 if < 1 it has to mail me. Please help me
Thanks
Rajesh

Declare @L int SELECT @L=DATALENGTH (Responsibility) FROM Positiontitle
WHERE PosName = ‘planner2’ if (@L) > 1
exec master..xp_sendmail ‘[email protected]‘, ‘The Planner2 record length in responsibility table are less than 1’ Madhivanan Failing to plan is Planning to fail
PERFECT!!!!!!!
Thank a million for your help Madhivanan.
Well. You need to look for variables in sql server help file for more examples Madhivanan Failing to plan is Planning to fail
]]>