|
Group: StrataFrame Users
Posts: 430,
Visits: 507
|
Hi Edhy. I have established what the problem here is , but dont know how to fix it.
In my Select Command, depending on a parameter passed into the stored procedure, i need to change the Field from the Table that is used. Sometimes it may be the Order date, sometimes the Despatch date and sometimes the Invoice date. I pass in a parmater and then have a series of Ifs to store the filed name into a variable. Then, because I am using the variable in the Select string, and not the actual Field name, this gives the error. Here is an example of a cut doen SP which will give an error:
ALTER PROCEDURE [dbo].[TestSPR] @Paramdate Date AS BEGIN SET NOCOUNT ON; --SELECT * FROM ITR WHERE ITR_ORDDAT >= @Paramdate (This command works Fine) DECLARE @Mydate VARCHAR set @MyDate = 'ITR_ORDDAT' SELECT * FROM ITR WHERE @MyDate >= @Paramdate // This Line gives an error END
So if I use SELECT * FROM ITR WHERE ITR_ORDDAT >= @Paramdate ...... works fine
If I store 'ITR_ORDDAT' into @MyDate and run the select (as above) , gives an conversion string to date/Time error.
|