| | |
dynamic sql query...
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 2
Reputation:
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
MS SQL Syntax (Toggle Plain Text)
declare @column_name nvarchar(10) SET @column_name = 'original' SELECT @column_name FROM DATA
any ideas ??
•
•
Join Date: Feb 2008
Posts: 42
Reputation:
Solved Threads: 13
MS SQL Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- 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)
| Thread Tools | Search this Thread |





