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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Dynamic SQL

Author  Topic 

mhg1063
Starting Member

27 Posts

Posted - 2004-07-19 : 14:09:38
I'm trying to Create a function. I want the user to input a datefield and a number. The number will determine the operator < ,> <=,>=, = . I want to compare the input date to another date that changes daily using dynamic sql. However, I can get it to work.
I have a statement similar too

SET @sql = 'IF ' + @asbusday + @sign1 + @aisdate +
'SET ' + @ans + ' = ''y'''

Any suggestions would be appreciated:

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-07-19 : 14:10:43
Could you post what you have for the function? And also provide a few examples?

Tara
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-07-19 : 14:12:59
You can't execute dynamic SQL in a function. Try:

Select @ans = case
when @sign1 = 1 and @asbusday < @aisdate then 'y'
when @sign1 = 2 and @asbusday > @aisdate then 'y'
when @sign1 = 3 and @asbusday <= @aisdate then 'y'
when @sign1 = 4 and @asbusday >= @aisdate then 'y'
when @sign1 = 5 and @asbusday = @aisdate then 'y'
else 'n' end


Corey
Go to Top of Page

mhg1063
Starting Member

27 Posts

Posted - 2004-07-19 : 14:38:55
Thanks Corey and Tduggan for responding,
Case worked.
Go to Top of Page
   

- Advertisement -