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

where clause using a variable not working 1

Status
Not open for further replies.

nsanto17

IS-IT--Management
Mar 14, 2005
616
US
I am using the @query Paramater in sp_send_dbmail and for reason i can't use a variable in my where clause

Code:
set @Query = 'SELECT     *
					FROM         Email_Log.dbo.Email_Log
						Where ID = (''@Q_ID'')'

its got to be syntax...

Any ideas?
 
Depending on the data type of @Q_ID...

If Q_ID is a number...
Code:
set @Query = 'SELECT * 
FROM Email_Log.dbo.Email_Log 
Where ID = ' + Convert(VarChar(20), @Q_ID)

Or


if @Q_ID is a string...
Code:
set @Query = 'SELECT * 
FROM Email_Log.dbo.Email_Log 
Where ID = ''' + @Q_ID + ''''


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top