|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Conversion queryI have 2 date variables passed into my store procedure as follows
@StartDate datetime, @EndDate datetime however I am getting a conversion error when running the command below which says "Syntax error converting datetime from character string" PRINT ('INSERT INTO ' + @NewSubsList + '(SubRef) SELECT DISTINCT SubRef FROM Subscriptions WHERE (PubCode = ' + @PubCode + ') AND DateEntered >= ' + @StartDate + ') AND (DateEntered <= ' + @EndDate + ')') Any suggestions would be welcome. Thanks You have to explictly cast the datetime values to characters like so
PRINT ('INSERT INTO ' + @NewSubsList + '(SubRef) SELECT DISTINCT SubRef FROM Subscriptions WHERE (PubCode = ' + @PubCode + ') AND DateEntered >= ' + Cast(@StartDate As VarChar(20)) + ') AND (DateEntered <= ' + Cast(@EndDate As VarChar(20)) + ')') Thomas Show quoteHide quote "Pete" <P***@discussions.microsoft.com> wrote in message news:E78EE524-27E2-47AF-96E4-60B250AFA884@microsoft.com... >I have 2 date variables passed into my store procedure as follows > > @StartDate datetime, > @EndDate datetime > > however I am getting a conversion error when running the command below which > says "Syntax error converting datetime from character string" > > PRINT ('INSERT INTO ' + @NewSubsList + '(SubRef) > SELECT DISTINCT SubRef > FROM Subscriptions > WHERE (PubCode = ' + @PubCode + ') AND DateEntered >= ' + @StartDate + > ') AND (DateEntered <= ' + @EndDate + ')') > > Any suggestions would be welcome. > > Thanks
Other interesting topics
Query Assistance - Average Days Between Services
Problem with EXEC command Inserting records in a User-Defined Function Convert VB.NET to TSQL PROC & Reference a Proc from another Proc Small letter and numeric number in Tabel field Grouping Data By Weeks Set Operations in TSQL Need help with SELECT statement Please. Integer Index -vs- nVarChar(50) index.... duplicates |
|||||||||||||||||||||||