l_agmon
asked on
Simple Sql Conditional Select
I have a table of the following type:
int Linkid
int LinkType
datetime LinkChangeddate
datetime LinkCheckeddate
How can I write a stored procedure which selects rows based on LinkType's Value.
For each row, it is returned if:
a. If Linktype = 1 and Today-LinkCheckeddate > 3 days
b. If Linktype = 2 and Today-LinkCheckeddate > 7 days
b. If Linktype = 3 and LinkChangeddate>LinkChecke ddate
Thanks!
L.Agmon.
int Linkid
int LinkType
datetime LinkChangeddate
datetime LinkCheckeddate
How can I write a stored procedure which selects rows based on LinkType's Value.
For each row, it is returned if:
a. If Linktype = 1 and Today-LinkCheckeddate > 3 days
b. If Linktype = 2 and Today-LinkCheckeddate > 7 days
b. If Linktype = 3 and LinkChangeddate>LinkChecke
Thanks!
L.Agmon.
Oops. Error on my sample to execute it. Instead use:
EXEC up_LinkCheckDate 1
EXEC up_LinkCheckDate 2
or
EXEC up_LinkCheckDate 3
EXEC up_LinkCheckDate 1
EXEC up_LinkCheckDate 2
or
EXEC up_LinkCheckDate 3
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CREATE PROCEDURE up_LinkCheckDate @LinkType tinyint AS
IF @LinkType = 1 OR @LinkType = 2
SELECT Linkid, LinkType, LinkChangeddate, LinkCheckeddate
FROM LinkTable
WHERE DateDiff(d,GetDate(),LinkC
ELSE
SELECT Linkid, LinkType, LinkChangeddate, LinkCheckeddate
FROM LinkTable
WHERE LinkChangeddate > LinkCheckeddate
--sample to use the procedure
--EXECUTE up_link 1