Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir/Mam


I am Shailendra Singh and I am new to .Net .How can get ROWINDEX and how can use of rowindex insert database in table.I want to retrive rowindex from database table by unique key(id).Any one help me.






Thanks In Advance
Posted

use select @@identity in your stored procedure

and you will get the last inserted row index ...
 
Share this answer
 
Get the maximum ID using max fuction from respective table
declare @rowIndex int
Select @rowIndex = max(columnName) from TableName

Use the @rowIndex in your insert query
Insert into tableName (columnName) values (@rowIndex)
 
Share this answer
 
by using this way, u can retrive last rowindex of perticular table

SQL
if(@CMD = 'INSERT')
BEGIN
INSERT INTO table_name(column_name) 
    VALUES(Add_your_value)

SET @_RGP = SCOPE_IDENTITY()

SELECT @_RGP AS last_rowindex

END
 
Share this answer
 
see below

SQL
Declare @t_ID int

-- Write your insert query here like..
INSERT INTO TABLE (c1,c2,c3..) VALUES ('c1',c2,'c3'..)
SELECT @t_ID=@@IDENTITY

-- Use that id into your insert query
INSERT INTO TABLE1 (Column1) VALUES (@t_ID)
INSERT INTO TABLE2 (Column2) VALUES (@t_ID)
 
Share this answer
 
v2
My understanding is that you have a table with an identity column (auto number) and you want to retrieve the row index for a given identity value ?

and hope this helps

SQL
WITH MyTemp AS
(
    SELECT <<YOUR IDENTITY COLUMN>>,<< COLUMN 2>>,<<COLUMN  3>>
    ROW_NUMBER() OVER (ORDER BY <<YOUR IDENTITY COLUMN>>) AS 'RowNumber'
    FROM Orders
)
SELECT *
FROM MyTemp
where <<YOUR IDENTITY COLUMN>>=10251



folowowing is the query you can run on the SQL Server northwind database and see how it works

SQL
WITH OrderedOrders AS
(
    SELECT OrderID,OrderDate,
    ROW_NUMBER() OVER (ORDER BY orderid) AS 'RowNumber'
    FROM Orders
)
SELECT *
FROM OrderedOrders
--where OrderID=10251
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900