December 20, 2008 at 8:05 am
Hello ,
I want to get the desired product ID
with a condition about Row Index of the results ,
is it possible inside an sproc or not ,
I know that this code ( the end part ) is not correct ,
but it shows want I want ,
It's also appreciable to know alternate ways to do that by code (CLR )
this will be a part of an asp.net 2.0 application
and just I want to get a productID at last
-----------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROC [dbo].[GetSelRowProductID3]
( @TagSelected nvarchar(20) ,
@RowNum int
)
AS
BEGIN
DECLARE @ProductsX TABLE
(
ProductID INT ,
RowNumber INT
)
INSERT INTO @ProductsX
SELECT
ROW_NUMBER() OVER (ORDER BY id) AS Row , id
FROM Products p
JOIN [TagProducts] tp ON p.[id]=tp.[ProductID]
JOIN [Tags] t ON t.[TagID]=tp.[TagID]
WHERE @TagSelected = t.[TagTitle]
SELECT id FROM @ProductsX
WHERE Row = @RowNum
END
December 20, 2008 at 2:42 pm
Can you post the table definitions and some sample data as per the link in my signature block so that someone can properly assist you?
December 20, 2008 at 4:41 pm
It'll work if you put the SELECT LIST into the same order as the COLUMN LIST in the table definition. It would be better if the INSERT had a discrete COLUMN LIST.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 28, 2008 at 5:15 am
I solved the issue next to my post ,
Jeff Moden is right ,
the problem was because of ther order of what I entered ,
and also one of the variables name ,
excuse me for the delay ,
really thanks
December 28, 2008 at 8:54 am
Thanks for the feedback. Just remember that order typically means nothing in a database and it theoretically could change at any time. It's always best to have a Column List on Inserts.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply