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)
 Dynamic Query using table columns

Author  Topic 

amalipriya
Starting Member

3 Posts

Posted - 2012-06-07 : 16:49:05
Dear All

I am using visual studio 2010 and sql server 2005. I am creating dynamic Dashboard Setup.

The follows is my Dashboard Setup table structure:

Purpose of the table is to build where condition.My Select Query will be static.


SegementID FetchTable Parametername ParameterValue ParaType
1 TB_Stock ExpiryDate 10 Date
1 TB_Stock Status 1 ComboBox
1 TB_Branch BranchName TestBranch TextBox
2 TB_WareHouse WareHouse TestWareHouse TextBox
and so on..



My result should be as follows:
(Expiry Date is my datetime datatype(in the TB_Stock), but user will give only the no. of days. For example if he gives 10 then FROM Date and TO DATE should be Calculated based on system date while generating the where query)

This has to be build based on Segment ID.This above table has SegmentID 1 as three times. so I have combine three rows into one where Condition.

(My where condition should be as follows for SegmentID 1)

Where(TB_Stock_Details.ExpiryDate between '4/4/2011'and '4/4/2012')
AND (TB_Stock.Status =1)
AND (TB_Branch.BranchName='TestBranch'


(Likewise for SegmentID 2)

Where TB_WareHouse.WareHouse='TestWareHouse'

How do I achieve this? Please do help me as soon as possible. I know I have to apply while loop for SegmentID.But How?


Regards
Sona












visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-07 : 22:53:11
does look like a good design. using current method you've to make use dynamic sql for generating dynamic filters.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -