golferdude1971
Programmer
I use MS-SQL 100% of the time, and I have a project that I have to convert from SQL to Access. I have little knowledge about Access queries, and I was wondering if the stored procedure below would work in Access
CREATE PROCEDURE MoveItems
(
@direction int,
@RID_IN int
)
AS
/*
declare @direction int
select @direction = 1 --up 1 // down 2
declare @RID_IN int
select @RID_IN = 7
*/
declare @MaxORder int
declare @MinORder int
select @MinORder = min(listorder) from gnt where status = 1
select @MaxORder = max(listorder) from gnt where status = 1
declare @prevorder int
select @prevorder = listorder from gnt where rid = @RID_IN and status = 1
declare @replaceRID int
declare @replaceRID_Order int
if @direction = 1
begin
if @prevorder > @MinORder
begin
select @replaceRID = (select top 1 rid from gnt where @prevorder > listorder and status = 1 order by listorder desc)
select @replaceRID_Order = listorder from gnt where rid = @replaceRID and status = 1
/*
print '@MinORder =' + cast(@MinORder as varchar)
print '@MaxORder=' + cast(@MaxORder as varchar)
print '@prevorder =' + cast(@prevorder as varchar)
print '@replaceRID=' + cast(@replaceRID as varchar)
print '@replaceRID_Order=' + cast(@replaceRID_Order as varchar)
*/
update gnt
set listorder = @replaceRID_Order
where rid = @RID_IN
update gnt
set listorder = @prevorder
where rid = @replaceRID
end
end
if @direction = 2
begin
if @prevorder < @MaxORder
begin
select @replaceRID = (select top 1 rid from gnt where @prevorder < listorder and status = 1 order by listorder )
select @replaceRID_Order = listorder from gnt where rid = @replaceRID and status = 1
/*
print '@prevorder =' + cast(@prevorder as varchar)
print '@replaceRID=' + cast(@replaceRID as varchar)
print '@replaceRID_Order=' + cast(@replaceRID_Order as varchar)
*/
update gnt
set listorder = @replaceRID_Order
where rid = @RID_IN
update gnt
set listorder = @prevorder
where rid = @replaceRID
end
end
GO
CREATE PROCEDURE MoveItems
(
@direction int,
@RID_IN int
)
AS
/*
declare @direction int
select @direction = 1 --up 1 // down 2
declare @RID_IN int
select @RID_IN = 7
*/
declare @MaxORder int
declare @MinORder int
select @MinORder = min(listorder) from gnt where status = 1
select @MaxORder = max(listorder) from gnt where status = 1
declare @prevorder int
select @prevorder = listorder from gnt where rid = @RID_IN and status = 1
declare @replaceRID int
declare @replaceRID_Order int
if @direction = 1
begin
if @prevorder > @MinORder
begin
select @replaceRID = (select top 1 rid from gnt where @prevorder > listorder and status = 1 order by listorder desc)
select @replaceRID_Order = listorder from gnt where rid = @replaceRID and status = 1
/*
print '@MinORder =' + cast(@MinORder as varchar)
print '@MaxORder=' + cast(@MaxORder as varchar)
print '@prevorder =' + cast(@prevorder as varchar)
print '@replaceRID=' + cast(@replaceRID as varchar)
print '@replaceRID_Order=' + cast(@replaceRID_Order as varchar)
*/
update gnt
set listorder = @replaceRID_Order
where rid = @RID_IN
update gnt
set listorder = @prevorder
where rid = @replaceRID
end
end
if @direction = 2
begin
if @prevorder < @MaxORder
begin
select @replaceRID = (select top 1 rid from gnt where @prevorder < listorder and status = 1 order by listorder )
select @replaceRID_Order = listorder from gnt where rid = @replaceRID and status = 1
/*
print '@prevorder =' + cast(@prevorder as varchar)
print '@replaceRID=' + cast(@replaceRID as varchar)
print '@replaceRID_Order=' + cast(@replaceRID_Order as varchar)
*/
update gnt
set listorder = @replaceRID_Order
where rid = @RID_IN
update gnt
set listorder = @prevorder
where rid = @replaceRID
end
end
GO