Get Previous number
Database
2
Posts
2
Posters
0
Views
1
Watching
-
I have select query and I am getting results like 2 4 6 If I Pass 6 as Parameter then i need to get previous number of 6 i,e 4. If 9 then it has to give 0. How can I write the query for this in Sql Server 2005
-
I have select query and I am getting results like 2 4 6 If I Pass 6 as Parameter then i need to get previous number of 6 i,e 4. If 9 then it has to give 0. How can I write the query for this in Sql Server 2005
DECLARE
@ID INTSET @ID = 4
SELECT TOP 1 ID
FROM tablename
WHERE ID < @ID
ORDER BY ID DESCTest the result for null and replace with 0 OR Put the results into a variable in the procedure and test the variable and return the results.
Never underestimate the power of human stupidity RAH