Sql Server Not Returning Value

Posted by Shoyebaziz123 under Sql Server on 9/27/2012 | Points: 10 | Views : 880 | Status : [Member] | Replies : 2
Hi All,
i have written this query but its not working

declare @sTableName varchar(250)=null;
set @sTableName= 'tbl_WaterTurbidity';
declare @dt1 datetime=null ;
set @dt1='9/1/2012'
declare @dt2 datetime=null;
set @dt2='9/30/2012'

EXEC( 'select ISNULL(count(IsActive),0) as Act from '+ @sTableName +
' where IsActive=0 ' + ' AND (DateOfAnalysis between ' + @dt1 +
' AND '+ @dt2 +')' ) ;

purpose of query is passing table name as parameter to sp.

while running this query it shows an error of

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '1'.

if i change '9/1/2012' here from date 1 to 7,8,9 .. etc it shows respected error
means if i set '10/3/2012' then Incorrect syntax near '3'.

i have tried here several types of date maeans changing yyyy-mm-dd fashion to dd-MM-yyyy .. but there is same error .

what is the reason ?

Thanks




Responses

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this

http://www.dotnetfunda.com/codes/code3279-how-to-declare-table-and-assign-select-query.aspx


Mark as Answer if its helpful to you

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response