R
Ryan Ternier
Hey,
I'm trying to wrap my head around this and it's hurting hard.
I need to swap 2 rows in a table.
This is basically a list system, where a user can click an up arrow, and the
current record gets -1 in priority.
Here's my code so far.
----------------
CREATE procedure spAdjustQuickLink
@intQID1 int
as
declare @intQID2 int
SET @intQID2 =(SELECT UserQuickLinkID
FROM tblUserQuickLink
WHERE LinkOrder = (SELECT LinkOrder
FROM tblUserQuickLink
WHERE UserQuickLInkID = @intQID1) )
if (@intQID1 = 1)
begin
raiserror('Cannot change link order',-1,-1)
return(1)
end
UPDATE tblUserQuickLink
SET LinkOrder = (LinkOrder - 1)
WHERE UserQuickLinkID = @intQID1
UPDATE tblUserQuickLInk
SET LinkOrder = (LinkOrder +1)
WHERE UserQuickLinkID = @intQID2
GO
I'm trying to wrap my head around this and it's hurting hard.
I need to swap 2 rows in a table.
This is basically a list system, where a user can click an up arrow, and the
current record gets -1 in priority.
Here's my code so far.
----------------
CREATE procedure spAdjustQuickLink
@intQID1 int
as
declare @intQID2 int
SET @intQID2 =(SELECT UserQuickLinkID
FROM tblUserQuickLink
WHERE LinkOrder = (SELECT LinkOrder
FROM tblUserQuickLink
WHERE UserQuickLInkID = @intQID1) )
if (@intQID1 = 1)
begin
raiserror('Cannot change link order',-1,-1)
return(1)
end
UPDATE tblUserQuickLink
SET LinkOrder = (LinkOrder - 1)
WHERE UserQuickLinkID = @intQID1
UPDATE tblUserQuickLInk
SET LinkOrder = (LinkOrder +1)
WHERE UserQuickLinkID = @intQID2
GO