Hello,
I've got a MS SQL procdure to write that i sa bit above my head. Any help would be greatly appreciated. I am working on this for a web site I'm building, and the DB guy at the company I'm working for works mostly in RPG, so it's up to me.
I'm really only working with one table in this query.
I am passing in four parameters. The first three are Group, Category, and Class. An item cannot have a Category with out a Group, nor a class without a category. This is already verified, so doesn't need any error checking.
The first three are pretty straighforward. This is how I was building the SQL in c# for testing. This should explain what I want to do better than I can:
That part of it is not too bad. The real problem is the fourth parameter. There is a finish field in the itemMaster that contains a single digit int, which stands for a particular finish. The fourth parameter is the concatination of finishes that should be included in the search.
For example, if the parameter was "24039", that would indicate that the finishes 2, 4, 3, and 9 should be included in the search. A zero would be ignored. I understand the substring function in SQL, but I don't understand how conditionals in SQL work well enough to do this.
Any pointer in the right direction would be greatly appreciated!
I've got a MS SQL procdure to write that i sa bit above my head. Any help would be greatly appreciated. I am working on this for a web site I'm building, and the DB guy at the company I'm working for works mostly in RPG, so it's up to me.
I'm really only working with one table in this query.
I am passing in four parameters. The first three are Group, Category, and Class. An item cannot have a Category with out a Group, nor a class without a category. This is already verified, so doesn't need any error checking.
The first three are pretty straighforward. This is how I was building the SQL in c# for testing. This should explain what I want to do better than I can:
Code:
string sqlStatement = "Select OrderCode From itemMaster";
if (productGroup != "")
{
sqlStatement = sqlStatement + " WHERE [Group]='" + productGroup + "'";
if (productCategory != "")
{
sqlStatement = sqlStatement + " AND [Category]='" + productCategory + "'";
if (productClass != "")
{
sqlStatement = sqlStatement + " AND [Class]='" + productClass + "'";
}
}
}
That part of it is not too bad. The real problem is the fourth parameter. There is a finish field in the itemMaster that contains a single digit int, which stands for a particular finish. The fourth parameter is the concatination of finishes that should be included in the search.
For example, if the parameter was "24039", that would indicate that the finishes 2, 4, 3, and 9 should be included in the search. A zero would be ignored. I understand the substring function in SQL, but I don't understand how conditionals in SQL work well enough to do this.
Any pointer in the right direction would be greatly appreciated!