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 |
|
kurtgr
Starting Member
25 Posts |
Posted - 2009-07-26 : 17:49:14
|
| Hi AllI am have a problem which i seem not to be able to solve. below is my codeDECLARE @EmployeeId INT, @EmployeeTypeId CHAR(1), @GenderId CHAR(1),@Age INT, @WageTypeId Char(1), @DaysEmployed INT @Command NCHAR(1000), @Filter VARCHAR(200)SET @Command = 'SELECT LeaveTypeName,LeaveTypeId,WageTypeEligible, ' + 'EmployeeTypesEligible,MinDaysOfEmploymentForEligibility,AgeRange '+'FROM #Temp1 T INNER JOIN AgeRange A ' + 'ON T.AgeRange = A.AgeId ' SET @Filter = ' WHERE MinDaysOfEmploymentForEligibility <= ' +@DaysEmployed SET @Command = RTRIM(@Command) + ' ' + LTRIM(@Filter) EXEC( @Command )I am getting this errorConversion failed when converting the varchar value ' WHERE MinDaysOfEmploymentForEligibility <= ' to data type int.Just to note MinDaysOfEmploymentForEligibility is a INT field in the table Thanks in advance for ur help |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-07-26 : 17:58:34
|
quote: SET @Filter = ' WHERE MinDaysOfEmploymentForEligibility <= ' +@DaysEmployed
SET @Filter = ' WHERE MinDaysOfEmploymentForEligibility <= ' + Convert(varchar(500), @DaysEmployed) |
 |
|
|
kurtgr
Starting Member
25 Posts |
Posted - 2009-07-26 : 18:03:55
|
| Thanks very much but could u say why it did not work the way i had it |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-07-26 : 18:30:16
|
| because @Filter is a string. You're trying to append an integer value to a string. Need to explicitly cast the int to varchar to build the string with int in it. |
 |
|
|
kurtgr
Starting Member
25 Posts |
Posted - 2009-07-26 : 18:31:11
|
| Ok understood and Thanks again |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-07-26 : 18:33:49
|
You're welcome. Glad to help |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-27 : 02:35:14
|
| www.sommarsko.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|