Author |
Topic |
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-02-16 : 01:40:47
|
hi,I need a procedure which retrieves specified no.of columns starting from specified position from a specified table. Can any one help me.Thanks in Advance......... |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-16 : 01:47:29
|
Specified no of columns?didnt understand that? did you mean specified no of rows? or columns within a row?Explain |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-02-16 : 02:29:25
|
quote: Originally posted by visakh16 Specified no of columns?didnt understand that? did you mean specified no of rows? or columns within a row?Explain
suppose assume there is a table emptable :empcol1 col2 col3 col4 col5 col645 34 12 6 99 10038 88 77 37 86 56then if i pass the values emp, 3,2the i should get the outputcol3 col412 677 37 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-16 : 23:03:24
|
Check this for getting idea on systems catalog views under INFORMATION_SCHEMAhttp://developer.mimer.com/documentation/html_91/Mimer_SQL_Engine_DocSet/Data_dic_views2.html |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
Qualis
Posting Yak Master
145 Posts |
Posted - 2008-02-18 : 10:03:55
|
Try:Create Procedure GetColumnList(@TableName varchar(100), @StartAtCol int, @ColumnList varchar(8000) OUTPUT)As Begin Declare @Result varchar(8000) Select @Result = Coalesce(@Result + ',', '') + SC.name From sysobjects so inner join syscolumns sc on so.id = sc.id Where SO.xtype = 'U' And SO.name = @TableName And SC.colorder >= @StartAtCol Order By SC.colorder Set @ColumnList = @ResultEnd--UsageDeclare @Result varchar(8000)Exec GetColumnList 'sysdtslog90', 3, @Result OUTPUTPrint @Result |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-02-19 : 04:30:45
|
quote: Originally posted by Qualis Try:Create Procedure GetColumnList(@TableName varchar(100), @StartAtCol int, @ColumnList varchar(8000) OUTPUT)As Begin Declare @Result varchar(8000) Select @Result = Coalesce(@Result + ',', '') + SC.name From sysobjects so inner join syscolumns sc on so.id = sc.id Where SO.xtype = 'U' And SO.name = @TableName And SC.colorder >= @StartAtCol Order By SC.colorder Set @ColumnList = @ResultEnd--UsageDeclare @Result varchar(8000)Exec GetColumnList 'sysdtslog90', 3, @Result OUTPUTPrint @Result
Msg 134, Level 15, State 1, Procedure GetColumnList, Line 22The variable name '@Result' has already been declared. Variable names must be unique within a query batch or stored procedure.this is the error what iam getting. |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-02-19 : 04:34:40
|
quote: Originally posted by Qualis Try:Create Procedure GetColumnList(@TableName varchar(100), @StartAtCol int, @ColumnList varchar(8000) OUTPUT)As Begin Declare @Result varchar(8000) Select @Result = Coalesce(@Result + ',', '') + SC.name From sysobjects so inner join syscolumns sc on so.id = sc.id Where SO.xtype = 'U' And SO.name = @TableName And SC.colorder >= @StartAtCol Order By SC.colorder Set @ColumnList = @ResultEnd--UsageDeclare @Result varchar(8000)Exec GetColumnList 'sysdtslog90', 3, @Result OUTPUTPrint @Result
next even i tried with thisDeclare @CList varchar(8000)Exec GetColumnList 'tbl_abc_xyz', 3, @CList OUTPUTPrint @CListiam getting the following error Msg 217, Level 16, State 1, Procedure GetColumnList, Line 22Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32). |
|
|
Qualis
Posting Yak Master
145 Posts |
Posted - 2008-02-19 : 09:45:45
|
Execute each piece separately... The second piece is an example of usage. |
|
|
|