Having trouble converting @StartDate and @EndDate to the proper string in the concatenated string below, #1. I keep getting the following error:
"Conversion failed when converting date and/or time from character string."
#1
Declare @StartDate datetime,
@EndDate datetime,
@STRSQL As varchar(5000)
Set @StartDate='01/01/2015'
Set @EndDate='08/31/2015'
Set @STRSQL = @STRSQL + ' Select CusName from custable where p.Paid_DATE between Convert(varchar(10), ' + @StartDate + ',101) and Convert(varchar(10), ' + @EndDate + ',101)'
Execute(@STRSQL)
I have tried omitting Convert and still get the error message:
"Conversion failed when converting date and/or time from character string."
#2
When I do this it works
Declare @StartDate varchar(50),
@EndDate varchar(50),
@STRSQL As varchar(5000)
Set @StartDate='01/01/2015'
Set @EndDate='08/31/2015'
Set @STRSQL = @STRSQL + ' Select CusName from custable where p.Paid_DATE between ' + @StartDate + ' and ' + @EndDate + ''
Execute(@STRSQL)
#3
Without a concatenated string I can do this and get data:
Declare @StartDate datetime,
@EndDate datetime,
Set @StartDate='01/01/2015'
Set @EndDate='08/31/2015'
Select CusName from custable where p.Paid_DATE Between @StartDate and @EndDate
What do I need to do in #1 in the concatenated string to get results?
Since I modified the original select statement here to shorten the string I may have a misplace tick mark here but not in my original string meaning that what is here is not throwing an error due to that kind of syntax error.
TIA