I've got a stored procedure that is inserting empty strings for certain values.
Below is the relevant portion of the stored procedure. You can see that if key2 is NULL then we set it's value based on key1.
IF NOT EXISTS (SELECT * FROM myTable WHERE key1 = @key1)
INSERT INTO myTable (key1,key2)
VALUES (@key1, ISNULL(@key2,'abc'+LTRIM(STR(@key1,7,0))));
What I'd like to be able to do is set key2 using the same formula if key2 is null or an empty string.
For the sake of this question, let's assume I can't change the caller so I can get either an empty string or null in some cases, In the case where key2 isn't null or an empty string, then I want to insert it as is.
I'm sure there is an easy way to do this, but I don't really know enough sql to know what to search for.