-1

My error is in this part (select min(sc.name) from so.name ), how to solve it ? In the select I am getting the table and column name, in the same time i want to get the min value of the column from the table. Is that possible?.

   select so.name table_name , sc.name Column_name,(select min(sc.name) from  so.name )
   from sysindexes si, syscolumns sc, sysobjects so
   where si.indid < 2  -- 0 = if a table. 1 = if a clustered index on an allpages-locked table. >1 = if a nonclustered index or a clustered index on a data-only-locked table.
     and so.type = 'U' --U – user table
     and sc.status & 128 = 128 --(value 128) – indicates an identity column.
     and so.id = sc.id
     and so.id = si.id
Moudiz
  • 7,211
  • 22
  • 78
  • 156

1 Answers1

-1

So the problem is that You are trying to basically trying to do dynamic code where You try to select a column based on a table name from a system table. Problem is that SQL doesnt know that the 'so.name' you are referencing is a table (further more, sysobjects also contains procedures and functions). Rather than that, you should do an Inner join between sys.syscolumns and sys.systables based on object_id.

TheLJ
  • 11
  • 1