Click here to Skip to main content
14,665,095 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi experts,

Thank you for attention.


my table

id name loc branch
1 AB Kol
2 Den Den

if i give 0 as column index get 1,2

and how to get no of columns exist in a particular table


Thanks in advance.

please help
Posted
Updated 19-Jul-12 23:00pm
v2

Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this...

SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_CATALOG = 'database' AND TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'table'


Here is another link

sql authority[^]

Hope it helps...

Sebastian
   
v2
Comments
   
now,how to get value using column index not columnname
Espen Harlinn 20-Jul-12 10:03am
   
5'ed!
Sebastian T Xavier 20-Jul-12 12:21pm
   
Thanks ...
Rate this:
Please Sign up or sign in to vote.

Solution 2

Columns count:
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema=MyDatabase AND table_name = MyTable
   
Comments
Espen Harlinn 20-Jul-12 10:03am
   
5'ed!

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100