SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic operator in query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 12/01/2010 :  10:47:52  Show Profile  Reply with Quote
Hi i want to use operator dynamically in my query..
my data in table is like..

ID    speeds   speedOperator
1       52          >
3       45          >=
4       74          =
65      43          <


I want to use above table filteration like
select * from tablename where speeds [speedOperator] [someValue]

Please help it urgent. please :)

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 12/01/2010 :  10:53:15  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
will need either dynamic sql or a lot of if statements.
Actually I think you will have to loop through the table and execute each row.
Maybe create a function to which you pass the values and return a 1 or 0?



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nigelrivett on 12/01/2010 10:54:24
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 12/01/2010 :  12:12:00  Show Profile  Reply with Quote
Thanks for reply..
but isn't is any other way to achieve this dynamic operator..

please help any other way if you find...
Go to Top of Page

TimSman
Posting Yak Master

USA
127 Posts

Posted - 12/01/2010 :  12:15:58  Show Profile  Reply with Quote
I don't understand what you are trying to accomplish. You want to pass in a value, and use that value in a comparison statement that is build using the value from the speedOperator in the table, correct?

If so, I'm not sure how the data you get is going to be meaningful, as you never really know what you're going to get back.
Go to Top of Page

keyursoni85
Posting Yak Master

India
233 Posts

Posted - 12/01/2010 :  12:25:32  Show Profile  Reply with Quote
yes..
actually my comparison will be against one row..
I filter one unit's information
eg. speed = 17

then i match it with all records with specified criterias and operators
and then returns with matched criteria

It matches like below
select * from tbl_FilterCriteria
where @speed [operator] speed[table column name]
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000