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 |
|
Velnias
Yak Posting Veteran
58 Posts |
Posted - 2008-10-16 : 07:12:33
|
| What I wish to do is input 2 paramaters into sql.I.e End Date and Current Dateif Current Date > End Date return falseelse return trueAny IdeasSQL2005 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-10-16 : 07:24:56
|
| CREATE FUNCTION [dbo].[samplefn] ( @currentdate datetime, @enddate datetime )RETURNS VARCHAR(5)ASBEGIN return case when @currentdate>@enddate then 'true' else 'false' endENDselect [dbo].[samplefn] (getdate(),getdate()+1) |
 |
|
|
ForkandBeard
Starting Member
10 Posts |
Posted - 2008-10-17 : 16:56:40
|
| Or to use the SQL boolean...CREATE FUNCTION [dbo].[samplefn] ( @dte1 datetime , @dte2 datetime )RETURNS BITASBEGIN DECLARE @blnReturn BIT IF (@dte1 > @dte2) BEGIN SET @blnReturn = 0 END ELSE BEGIN SET @blnReturn = 1 END RETURN @blnReturnENDGOSELECT [dbo].[samplefn] (getDATE(),getDATE()-1)Many ThanksMitchellwww.forkandbeard.co.uk |
 |
|
|
onlyforme
Starting Member
25 Posts |
Posted - 2008-10-18 : 01:41:19
|
| select * from user_details where getdate()>dtae |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-18 : 01:49:02
|
quote: Originally posted by ForkandBeard Or to use the SQL boolean...CREATE FUNCTION [dbo].[samplefn] ( @dte1 datetime , @dte2 datetime )RETURNS BITASBEGIN DECLARE @blnReturn BIT IF (@dte1 > @dte2) BEGIN SET @blnReturn = 0 END ELSE BEGIN SET @blnReturn = 1 END RETURN @blnReturnENDGOSELECT [dbo].[samplefn] (getDATE(),getDATE()-1)Many ThanksMitchellwww.forkandbeard.co.uk
no need of if else...you could simply use case when just like what sakets have show in his post |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-18 : 01:49:34
|
quote: Originally posted by onlyforme select * from user_details where getdate()>dtae
did you read question at all? |
 |
|
|
ForkandBeard
Starting Member
10 Posts |
Posted - 2008-10-18 : 07:18:46
|
| My suggestion was just to illustrate the use of the BIT variable as opposed to a VARCHAR.Many ThanksMitchellwww.forkandbeard.co.uk |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-18 : 07:46:16
|
quote: Originally posted by ForkandBeard My suggestion was just to illustrate the use of the BIT variable as opposed to a VARCHAR.Many ThanksMitchellwww.forkandbeard.co.uk
Ok. i was just suggesting another way |
 |
|
|
|
|
|