July 5, 2012 at 1:18 pm
Lynn Pettis (7/5/2012)
Note, you may get duplicate rows of data if there are multiple matches, so I'm sure that there may be other ways to accomplish this. I am looking at another way as we speak.
Thank you, I'll be digesting the approach above to get a good understanding of it.
Thanks
July 5, 2012 at 1:19 pm
And I found it. Try this in place of my original code above.
DECLARE @StateFipsCSV varchar(500) = '01,03'
SELECT
*
FROM
[dbo].[ProductInventory] prdinv
WHERE
exists (SELECT instr.Item FROM dbo.DelimitedSplit8K(@StateFipsCSV,',') instr INNER JOIN
dbo.DelimitedSplit8K(prdinv.StateFips,',') dtstr ON instr.Item = dtstr.Item);
GO
July 5, 2012 at 1:42 pm
Lynn Pettis (7/5/2012)
And I found it. Try this in place of my original code above.
DECLARE @StateFipsCSV varchar(500) = '01,03'
SELECT
*
FROM
[dbo].[ProductInventory] prdinv
WHERE
exists (SELECT instr.Item FROM dbo.DelimitedSplit8K(@StateFipsCSV,',') instr INNER JOIN
dbo.DelimitedSplit8K(prdinv.StateFips,',') dtstr ON instr.Item = dtstr.Item);
GO
Wow. thank you so much that helped a lot. I didnt think of using an Inner Join in there. :blush:
Now I have to figure out how to translate an empty string into all values. :w00t:
July 5, 2012 at 2:02 pm
joe.eager (7/5/2012)
Lynn Pettis (7/5/2012)
And I found it. Try this in place of my original code above.
DECLARE @StateFipsCSV varchar(500) = '01,03'
SELECT
*
FROM
[dbo].[ProductInventory] prdinv
WHERE
exists (SELECT instr.Item FROM dbo.DelimitedSplit8K(@StateFipsCSV,',') instr INNER JOIN
dbo.DelimitedSplit8K(prdinv.StateFips,',') dtstr ON instr.Item = dtstr.Item);
GO
Wow. thank you so much that helped a lot. I didnt think of using an Inner Join in there. :blush:
Now I have to figure out how to translate an empty string into all values. :w00t:
If you meant that @StateFipsCSV = '', that's easy even though there are thoughs that would disagree.
DECLARE @StateFipsCSV varchar(500) = '01,03'
SELECT
*
FROM
[dbo].[ProductInventory] prdinv
WHERE
exists (SELECT instr.Item FROM dbo.DelimitedSplit8K(@StateFipsCSV,',') instr INNER JOIN
dbo.DelimitedSplit8K(prdinv.StateFips,',') dtstr ON instr.Item = dtstr.Item)
OR @StateFipsCSV = '';
GO
July 5, 2012 at 2:05 pm
Lynn Pettis (7/5/2012)
joe.eager (7/5/2012)
Lynn Pettis (7/5/2012)
And I found it. Try this in place of my original code above.
DECLARE @StateFipsCSV varchar(500) = '01,03'
SELECT
*
FROM
[dbo].[ProductInventory] prdinv
WHERE
exists (SELECT instr.Item FROM dbo.DelimitedSplit8K(@StateFipsCSV,',') instr INNER JOIN
dbo.DelimitedSplit8K(prdinv.StateFips,',') dtstr ON instr.Item = dtstr.Item);
GO
Wow. thank you so much that helped a lot. I didnt think of using an Inner Join in there. :blush:
Now I have to figure out how to translate an empty string into all values. :w00t:
If you meant that @StateFipsCSV = '', that's easy even though there are thoughs that would disagree.
DECLARE @StateFipsCSV varchar(500) = '01,03'
SELECT
*
FROM
[dbo].[ProductInventory] prdinv
WHERE
exists (SELECT instr.Item FROM dbo.DelimitedSplit8K(@StateFipsCSV,',') instr INNER JOIN
dbo.DelimitedSplit8K(prdinv.StateFips,',') dtstr ON instr.Item = dtstr.Item)
OR @StateFipsCSV = '';
GO
Yup Just typed that into management studio and then saw my notification email from this.
Thank you so much for all your help!
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply