GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 92 of 171    Print  
How to retrieving the data from 11th column to n th column in a table.

  
Total Answers and Comments: 11 Last Update: April 22, 2008     Asked by: Hokrani 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
July 20, 2006 01:48:42   #1  
abhisekh        

RE: How to retrieving the data from 11th column to n t...

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.


 
Is this answer useful? Yes | No
August 02, 2006 10:26:18   #2  
dmadhusudhanarao Member Since: August 2006   Contribution: 7    

RE: How to retrieving the data from 11th column to n t...

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.


 
Is this answer useful? Yes | No
August 14, 2006 09:04:26   #3  
mariashylaja Member Since: August 2006   Contribution: 5    

RE: How to retrieving the data from 11th column to n t...

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


 
Is this answer useful? Yes | No
September 07, 2006 04:00:59   #4  
tdas2004 Member Since: September 2006   Contribution: 5    

RE: How to retrieving the data from 11th column to n t...
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
 
Is this answer useful? Yes | No
September 07, 2006 07:39:07   #5  
Surya Prakash        

RE: How to retrieving the data from 11th column to n t...

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


 
Is this answer useful? Yes | No
September 21, 2006 01:03:19   #6  
Mrunal        

RE: How to retrieving the data from 11th column to n t...

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;


 
Is this answer useful? Yes | No
January 15, 2007 08:45:18   #7  
vijaya        

RE: How to retrieving the data from 11th column to n t...

hi

select column _name

from table_name WHERE COLUMN_NAME BETWEEN 11TH ROW and NTH ROW

ORDERBY COLUMN_NAME/


 
Is this answer useful? Yes | No
February 07, 2007 07:23:52   #8  
jagannath rao        

RE: How to retrieving the data from 11th column to n t...
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.
 
Is this answer useful? Yes | No
February 08, 2007 10:02:39   #9  
tdas2004 Member Since: September 2006   Contribution: 5    

RE: How to retrieving the data from 11th column to n t...
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
 
Is this answer useful? Yes | No
February 18, 2007 10:03:50   #10  
ddkdhar Member Since: June 2006   Contribution: 48    

RE: How to retrieving the data from 11th column to n t...
select * from
(select rownum r a.* from employees a)
where r between 11 and 40

 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape