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
 Transact-SQL (2005)
 Dynamically passing the columns

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2007-12-06 : 17:44:58
Can we pass the parameters in Stored procedure as table Field name and other their its value as another parameters.I have tried below query but it not giving the results.

Please help in rewriting the query


Declare @Field char(7)
Declare @Value varchar(7)

SET @LOCAL='TCT_CD1'
SET @Value='00001'

select Descr ='Total Count', Count(A.PNG) Count from TableA a
WHERE (@LOCAL=''OR @LOCAL = @Value)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-06 : 17:55:29
It would require dynamic SQL and is not recommended. Why do you require this type of query?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2007-12-06 : 19:54:26
Since the front applications developers has requirement
they have designed a Combo box which eventually select a fieldname from the list and enter the respective values in the textbox.
It should fetch the result.
They want me to write a stored procedure.
Instead of creating all the combobox lists as input parameter i thought
there can be better way.
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-12-06 : 21:24:19
sounds like a dynamic search condition: http://sommarskog.se/dyn-search.html




elsasoft.org
Go to Top of Page
   

- Advertisement -