Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2009-11-11 : 14:36:07
|
| I have code:declare @d varchar(7)select @d='2005/09'EXEC('select top 10 Claim_YearMonthfrom tblwhere Claim_YearMonth>' +@d)Claim_YearMonth is a varchar(7) like 'yyyy/mm'I got error.Msg 245, Level 16, State 1, Line 2Conversion failed when converting the varchar value '2004/03' to data type int.how I can fix this problem?Thanks.Jeff |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-11 : 14:42:56
|
declare @d varchar(7)select @d='2005/09'EXEC('select top 10 Claim_YearMonthfrom tblwhere Claim_YearMonth>''' +@d+'''') No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-11-11 : 14:43:08
|
| [code]declare @d char(7)set @d = '2009/12'exec('select top 10 Claim_YearMonthfrom tblwhere Claim_YearMonth > ''' + left(@d, 4) + right(@d, 2) + '01''')[/code] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-12 : 01:47:11
|
| Why are you using dynamic SQL?declare @d varchar(7)select @d='2005/09'select top 10 Claim_YearMonthfrom tblwhere Claim_YearMonth+'/01'>@d+'/01'It is better you always use datetime datatype to store datesMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|