Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query with column name as parameter Expand / Collapse
Author
Message
Posted Friday, September 3, 2010 3:29 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 18, 2015 5:52 AM
Points: 284, Visits: 1,258
Hi ,

I have a functios that will return the column name like

column1,column2,column3,column4

but I want to execute the select query in View with that functions

Example:

select d.function_name() from table_name

instead of
select column1,column2,column3,column4 from table_name

thanks









Many Thanks!
S.saravanan
“I am a slow walker, but I never walk backwards-
Abraham Lincoln”
Post #980093
Posted Friday, September 3, 2010 4:12 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, March 1, 2015 10:37 PM
Points: 2,262, Visits: 5,451
you cant do it that way.. using dynamic query u can build it..

declare @sql varchar(max)

set @sql = ''

select @sql = 'SELECT ' + dbo.fn_columns() + ' FROM Table'

PRINT @sql
--EXEC (@sql)


Post #980109
Posted Friday, September 3, 2010 7:59 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, March 18, 2015 5:52 AM
Points: 284, Visits: 1,258
Hi In veiw the sq server wont allow to use the declarations,



Many Thanks!
S.saravanan
“I am a slow walker, but I never walk backwards-
Abraham Lincoln”
Post #980218
Posted Friday, September 3, 2010 10:00 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 9:43 PM
Points: 856, Visits: 2,769
Saravanan_tvr (9/3/2010)
Hi In veiw the sq server wont allow to use the declarations,



Ok, so you've got a function that gives you a delimited list of columns.

And you want a view defined to dynamically use that list?

Why would you want to do this??? I think you're going to have to back up and explain to us what you're trying to accomplish and why because you can't do what you're trying to do, but there is almost certainly another way of accomplishing it (e.g. not using a function, not using a view, or using both but having the view contain all columns and using dynamic sql when selecting from the view)
Post #980325
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse