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 |
|
mxfrail
Yak Posting Veteran
84 Posts |
Posted - 2009-07-23 : 10:10:50
|
This is what I am trying to accomplish -CREATE FUNCTION ASP_JobDate( @DateEntered DATETIME, @PSIJobNo INT)RETURNS DATETIMEASBEGIN RETURN ( If SELECT jobdate from MailCoups.dbo.bbjthead.ljob where ljob = @PSIJobNo Else @DateEntered )END Basically I want to pass in 2 variables.If there is a jobdate in the first part I want to return the job date. If not return the @DateEntered that I originally passed in.Can someone quickly help me restructure this to make it work.thanks. |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-07-23 : 10:15:02
|
| [code]CREATE FUNCTION ASP_JobDate( @DateEntered DATETIME, @PSIJobNo INT)RETURNS DATETIMEASBEGINDeclare @jobdate datetime RETURN ( If EXISTS ( SELECT @jobdate =jobdate from MailCoups.dbo.bbjthead.ljob where ljob = @PSIJobNo)BEGIN @jobdate ENDELSE @DateEntered )END[/code] |
 |
|
|
mxfrail
Yak Posting Veteran
84 Posts |
Posted - 2009-07-23 : 10:22:06
|
| Oh awesome.I tried to punch that in ... get error -incorrect syntax near keyword if.line 13 incorrect syntax near "=". |
 |
|
|
ron2112
Starting Member
44 Posts |
Posted - 2009-07-23 : 10:22:36
|
| [code]CREATE FUNCTION ASP_JobDate( @DateEntered DATETIME, @PSIJobNo INT)RETURNS DATETIMEASBEGIN RETURN ISNULL((SELECT jobdate from MailCoups.dbo.bbjthead.ljob where ljob = @PSIJobNo) , @DateEntered)END[/code] |
 |
|
|
mxfrail
Yak Posting Veteran
84 Posts |
Posted - 2009-07-23 : 11:14:34
|
quote: Originally posted by ron2112
CREATE FUNCTION ASP_JobDate( @DateEntered DATETIME, @PSIJobNo INT)RETURNS DATETIMEASBEGIN RETURN ISNULL((SELECT jobdate from MailCoups.dbo.bbjthead.ljob where ljob = @PSIJobNo) , @DateEntered)END
Perfect thanks! |
 |
|
|
|
|
|