SET @Where = @Where + ' AND AA.TargetDate >= ''' + CAST(@FromDate as VARCHAR) + ''' and ' + ' AA.TargetDate <= ''' + CAST(@ToDate as VARCHAR) + ''''
Please inform what is wrong in this command.
Jun 29, 2010 at 05:25 AM
why don't you use sp_executesql rather than exec() ?
You can pass the @Fromdate and @ToDate in as a parameter
read this also http://www.sommarskog.se/dynamic_sql.html
Jun 29, 2010 at 09:54 AM
If you are trying to construct a string in this manner, make sure that none of the values are NULL. If any one of the variable values are null to start with, the entire SET statement will return a null.
Jun 29, 2010 at 11:32 AM
What is your initial value for the @Where variable? If you did not assign anything the result will be NULL Try assign initial value like declare @where nvarchar(500) SET @where=' '
Jun 29, 2010 at 11:50 AM
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
Once you sign in you will be able to subscribe for any updates here
Answers and Comments
Need long-form SQL discussion? SQLserverCentral.com is the place.
asked: Jun 29, 2010 at 05:25 AM
Seen: 739 times
Last Updated: Jun 29, 2010 at 05:25 AM
SQL Server 2008 and DB2 Stored procedures
Easy way to manage full database name in stored procedures and triggers?
can we provide output parameters and return statement to a SP at a time?
sum of fields from 2 different views
scalar variable declaration
Is there a way to change the columns to rows in a stored procedure?
how do you troubleshoot a procedure?
LINQ vs Stored Procedure
Stored proc execution times different on two machines
convert datetime error