•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 428,368 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,491 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1201 | Replies: 1
![]() |
•
•
Join Date: Oct 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi
I am trying to write a function in which I customize my select statement. But it is not working as i desire...
It is as
Here original is the name of one of the columns. I wanted to make it such that column_name can be assigned any of the column names and the same piece of code works only by changing the value of @column_name...but it is not working....
any ideas ??
I am trying to write a function in which I customize my select statement. But it is not working as i desire...
It is as
declare @column_name nvarchar(10) set @column_name = 'original' select @column_name from data
any ideas ??
•
•
Join Date: Feb 2008
Posts: 22
Reputation:
Rep Power: 1
Solved Threads: 5
create table #tmp (Code varchar(255), Price money, Date smalldatetime)
insert #tmp (Code, Price, Date)
select 'ProductA', 12.00, '12/10/2002' union all
select 'ProductA', 12.50, '01/15/2005' union all
select 'ProductA', 12.01, '01/02/2008' union all
select 'ProductB', 15.12, '12/01/2005' union all
select 'ProductB', 16.00, '01/09/2008' union all
select 'ProductB', 16.24, '01/15/2008'
declare @column_name nvarchar(10)
set @column_name = 'Code'
exec ('select ' + @column_name + ' from #tmp')
set @column_name = 'Price'
exec ('select ' + @column_name + ' from #tmp')
drop table #tmp Hence Wijaya
www.ex-Soft.tk
www.ex-Soft.tk
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- search data base (ASP.NET)
- Help in using SQL Query in Crstal report with VB.NET (VB.NET)
- Javascript Function return value into PHP or not ?? Please help !! (JavaScript / DHTML / AJAX)
- generating dynamic/runtime query (JSP)
- generating dynamic/runtime query (JSP)
- generating dynamic/runtime query (MySQL)
- Sql??????? (PHP)
- Dynamic Query (JSP)
- dynamic content from database, How? (Database Design)
Other Threads in the MS SQL Forum
- Previous Thread: MS SQL query using Max
- Next Thread: Setting variable within an exec (@sql)


Linear Mode