Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 4th, 2005, 10:17 AM
Authorized User
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get the last row and last column value


My Question is :

How to get the value of last row and the last column in a table when we don't know about the limit of rows and columns.

For eg., there is x(n) rows and y(n) columns, then i have to get the value of x(n)th and y(n)th value.

Expecting for the reply.


Ramkumar A D
Old April 4th, 2005, 06:34 PM
Authorized User
Join Date: Mar 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts


i can help you a little in this matter.
you can write a function which will return the column name
after you find the column name write dynamic SQL for selecting the value for that column and use order by clause and select top 1 row
you will get the specified value.

To find the last column here is script.

Suppose you are in Northwind Database and wanna find the last column of Orders Table then you can write as

select name from syscolumns
where colorder = (select max(colorder) from syscolumns where id = object_id('orders'))
and id = object_id('orders')

This will return the column name and you can use this column name to write the dynamic SQL.


Atul Kumar Sharma

Similar Threads
Thread Thread Starter Forum Replies Last Post
find the FIRST USED row/column? crmpicco Excel VBA 3 July 23rd, 2013 12:52 PM
Column to Row [email protected] Excel VBA 2 March 23rd, 2007 04:16 AM
Column to Row [email protected] SQL Server DTS 0 March 1st, 2007 10:57 AM
ROW COUNTER COLUMN ricespn SQL Server 2000 5 October 20th, 2006 06:36 PM
Read a column and Search Row by Row in another col AyatKh Excel VBA 2 January 26th, 2005 12:02 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.