Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Dynamic Column

Author  Topic 

just.net
Starting Member

24 Posts

Posted - 2010-05-25 : 08:42:55
Hi,

I have SP:

ALTER PROCEDURE [dbo].[GetDetails]
@startDate datetime,
@endDate datetime,
@columnName nvarchar(20) -- this is the issue
AS
BEGIN
SET NOCOUNT ON;
SELECT FirstName,
LastName,
Currency,
TotalRoomsPrice
FROM [ReportCurreDemo]

-- this is the issue
WHERE (@columnName BETWEEN @startDate AND @endDate)
-- this is the issue


How can i do this?
(select from column but with parameter).

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-25 : 09:01:34
One way is to use dynamic sql but remember that dynamic sql have some side effects.

Edit: Refer the link for more information on dynamice sql. http://www.sommarskog.se/dynamic_sql.html

Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-25 : 09:03:00
This is only possible with dynamic sql.
See here:
http://www.sommarskog.se/dynamic_sql.html


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-25 : 09:03:29



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -