• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ignoring SQL parameters

 
Nick Potter
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have this statement for example:

SELECT * FROM mytable WHERE col1='val1' AND col2='val2';

one of the parameters could be null and in this case i'd like it ignored. How can i do this without using ifs, since in the code i actually have 7 parameters and it's a hassle to check if every parameter is null;

Thanks
 
Jan Cumps
Bartender
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i actually have 7 parameters and it's a hassle to check if every parameter is nul
I'm afraid that you will have to go through the hassle. How would you resolve this without checking it in your code, and dynamically creating the sql statement?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic