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.
| Author |
Topic |
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2009-03-20 : 03:28:08
|
| CREATE PROCEDURE [dbo].[SP_GetCountryData] @Zipcode varchar(20), @QueryStr varchar(100)ASBEGIN SELECT TOP 1 WITH TIES theValue,theCol FROM (SELECT * FROM Tbl_Country WHERE Zip_Final = @Zipcode) AS t1 UNPIVOT(theValue FOR theCol IN (' + @QueryStr + ')) AS u ORDER BY theValue DESCENDmy requirement is i want to use the dynamic query string in @QueryStr.The input for @QueryStr will be t1.INDI,t1.CHIN,t1.JPANG. Satish |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2009-03-20 : 05:20:36
|
| try with this.CREATE PROCEDURE [dbo].[SP_GetCountryData] @Zipcode varchar(20),@QueryStr varchar(100)ASBEGIN exec('SELECT TOP 1 WITH TIES theValue,theCol FROM (SELECT * FROM Tbl_Country WHERE Zip_Final ='+ @Zipcode +') AS t1UNPIVOT(theValue FOR theCol IN (' + @QueryStr + ')) AS u ORDER BY theValue DESC')ENDKarthik |
 |
|
|
|
|
|