Home SQL if statment
Reply: 0

SQL if statment

user9756
1#
user9756 Published in September 21, 2018, 8:04 am

I have this SQL query:

Select 
   * from dbo.Users 
WHERE 
   numOfScans == 0 feedback >= {0} 
AND 
   feedback <= {1} 
ORDER BY 
   lastScan ASC

It bring me all the users that the numOfScans is zero. I have another case that if this SELECT bring me zero results so i don't want to use numOfScans, something like:

Select 
  * from dbo.Users 
WHERE 
  feedback >= {0} AND feedback <= {1} 
ORDER BY 
  lastScan ASC

It's possible to do this in the same query? Or I need a new query for that?

share|improve this question

closed as unclear what you're asking by mjwills, Patrick, RajeshKumar R, phatfingers, user987339 Feb 16 at 15:03

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Which dbms are you using? – jarlh Feb 14 at 8:59
  • Add some sample table data and the expected result. Formatted text please, not images. – jarlh Feb 14 at 9:00
  • 1
    (OT) A {0} suggests that you are using String.Format to build your query. Please use parameters instead - look up on Sql Injection – Hans Kesting Feb 14 at 9:40
  • numOfScans == 0 feedback that looks like odd SQL syntax to me. – mjwills Feb 14 at 10:16
  • It would be awesome if you could show 15 lines of sample data, and explain the results you are expecting to see in your query based on those 15 lines of sample data. – mjwills Feb 14 at 10:16

4 Answers 4

active oldest votes
up vote 1 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.323138 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO