How to retrieving the data from 11th column to n th column in a table.

Showing Answers 1 - 11 of 11 Answers

abhisekh

  • Jul 20th, 2006
 

select * from emp where rowid in ( select  rowid  from emp where rownum <=&upto
minus
select rowid from emp where rownum <&startfrom)

from this you can select between any range.

  Was this answer useful?  Yes

suppose emp table is there.

assume that 11th column is ename nth column is some dump column.

now i want to insert the name column into dumpcolum. then simply execute the query.

insert into emp(dump) values select ename from emp

Thanks & Regards

Madhu D.

  Was this answer useful?  Yes

mariashylaja

  • Aug 14th, 2006
 

I assume that you ask how to get data of column X to column N. That is your query should be like "select column_11,column_12,column_13,...column_n from table_A".

But you are not sure about the name of the column which is at place 11, 12 and so on...

I hope you can not do this thru normal SQL. But you sould be able to do this using Dynamic SQL. Dynamic SQL lets you to frame your query during run time. so, get the total no of column that your table has, and go to the column 11,12, etc and finish framing your query. That should be the way.

Pls let me know if anyone knows any other way....

-Maria Antony

  Was this answer useful?  Yes

tdas2004

  • Sep 7th, 2006
 

Abhishek, your answer provides the rows from 'startfrom' to 'upto', but the question is to get the value of columns from say column 10 to column 20

  Was this answer useful?  Yes

Surya Prakash

  • Sep 7th, 2006
 

Try this


declare @a varchar(1000),@tblname varchar(100),@b nvarchar(1000)
declare @count int,@startcount int,@i int

select @i  = 1,
 @startcount = <Starting column no.>
 @a='',
 @tblname = '<table name>'

select @count = max(sc.colid) from sysobjects so join syscolumns sc on sc.id=so.id where so.name =@tblname
select @a = sc.name + ',' + @a from sysobjects so join syscolumns sc on sc.id=so.id where so.name =@tblname order by sc.colid desc

set @b=substring(@a,(patindex('%,%',@a)+1),len(@a))

while @startcount > @i + 1
begin
 set @b=substring(@b,patindex('%,%',@b)+1,len(@b))
 set @i=@i+1
end

set @b = N'select ' + left(@b,len(@b)-1) + ' from ' + @tblname

exec sp_executesql @b

  Was this answer useful?  Yes

Mrunal

  • Sep 21st, 2006
 

You can get the rows from 11 to n(12,13,14,15....) by using foll query-

select * from(select a.*, rownum r1 from

(select * from emp order by empno)a

where rownum <= &n)

where r1 >= 11;

  Was this answer useful?  Yes

vijaya

  • Jan 15th, 2007
 

hi

select column _name

from table_name WHERE COLUMN_NAME BETWEEN 11TH ROW and NTH ROW

ORDERBY COLUMN_NAME/

  Was this answer useful?  Yes

jagannath rao

  • Feb 7th, 2007
 

spool all the columns from 11th to Nth. After that just add "select" and comma after each column and from clause and just execute that query.

  Was this answer useful?  Yes

tdas2004

  • Feb 8th, 2007
 

Hi Mrunal,Your query does the same mistake as that of Abhishek's. It returns the rows from 11th to nth row and not the column values from 11th to nth

  Was this answer useful?  Yes

minak

  • Apr 22nd, 2008
 

declare @a varchar(1000),@tblname varchar(100),@b nvarchar(1000)
declare @startcol int,@i int, @endcol int

select @startcol = 11,
 @endcol =13,
 @a='',
 @tblname = '<tablename>'

select @a = sc.name + ',' + @a from syscolumns sc  where sc.id =object_id(@tblname) and sc.colid between  @startcol and @endcol order by sc.colid desc

set @b = N'select ' + left(@a,len(@a)-1) + ' from ' + @tblname

exec sp_executesql @b

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions