Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure, how to write an IF THEN

Status
Not open for further replies.

ironhide1975

Programmer
Feb 25, 2003
451
US
Question for ya, how do I modify this to if I pass a 1 in the PreviewCode variable it makes it

Posted = ‘1’

But if PreviewCode = 0 then is shows

Posted = ‘1 or 0’

USE [DatabaseName]

GO

/****** Object: StoredProcedure [dbo].[sp_GetPages] Script Date: 09/10/2007 13:52:52 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[sp_GetPages](

@GrabStart varchar(1000) = NULL,

@GrabEnd varchar(1000) = NULL,

@Position varchar(1000) = NULL,

@PageID int = NULL,

@PreviewCode varchar(1000) = NULL

)

AS

Select * From vwPageDesc

WHERE (DateOn -1) < @GrabStart AND (DateOff +1) > @GrabEnd AND Position = @Position AND fkPageInfo = @PageID AND Active = 1 AND Posted = @PreviewCode ORDER by ContentOrder, DateOn Desc, DateOff Desc




 
try this....

Code:
ALTER PROCEDURE [dbo].[sp_GetPages](
@GrabStart varchar(1000) = NULL,
@GrabEnd varchar(1000) = NULL,
@Position  varchar(1000) = NULL,
@PageID int = NULL,
@PreviewCode  varchar(1000) = NULL
)

AS

Select * 
From   vwPageDesc
WHERE  (DateOn -1) <  @GrabStart 
       AND (DateOff +1) > @GrabEnd 
       AND Position = @Position 
       AND fkPageInfo = @PageID 
       AND Active = 1 
       AND (
           (@Previewcode = '1' and Posted = 1)
           Or
           (@PreviewCode = '0' And Posted In (0,1))
           )
ORDER by ContentOrder, DateOn Desc, DateOff Desc

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Denis,

It wasn't clear (from the original post) what other possible values there can be.

In fact, it looks as if Posted can always be 1, but can only (also) be 0 if @PreviewCode is 0.

Code:
WHERE  (DateOn -1) <  @GrabStart
       AND (DateOff +1) > @GrabEnd
       AND Position = @Position
       AND fkPageInfo = @PageID
       AND Active = 1
       AND (
           Posted = 1
           Or @PreviewCode = '0' And Posted =0
           )

Besides, the requirement is...

Question for ya, how do I modify this to if I pass a 1 in the PreviewCode variable it makes it

Posted = ‘1’

But if PreviewCode = 0 then is shows

Posted = ‘1 or 0’

So..
[tt][blue]
@PreviewCode Posted
------------ ------
1 1
0 1 or 0
[/blue][/tt]

You wrote...
[tt][blue]and Posted <= @Previewcode [/blue][/tt]

If @PreviewCode = 1, then this would allows Posted to be 0 or 1, which is not what the OP was asking for.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top