Answered
Using quoted list with in()
I can't get this query to return results unless I manually
put in a list of zip codes
('80918','80917','80920','80902','80922','80907','80909','80919')
When I have the same list fed in as a variable SQL adds extra quotes to the list and I get no results. What do I need to do to prevent this?
declare
@ZipCodes varchar(300)
SELECT
StoreName,
Address,
City,
StateAbbreviation,
PostalCode,
PhoneNumber,
WebAddress
FROM
CatholicStores
JOIN
States
ON
State_Pk = State_Fk
WHERE
PostalCode IN (@zipcodes)
ORDER BY
PostalCode,
StoreName
When I have the same list fed in as a variable SQL adds extra quotes to the list and I get no results. What do I need to do to prevent this?
declare
@ZipCodes varchar(300)
SELECT
StoreName,
Address,
City,
StateAbbreviation,
PostalCode,
PhoneNumber,
WebAddress
FROM
CatholicStores
JOIN
States
ON
State_Pk = State_Fk
WHERE
PostalCode IN (@zipcodes)
ORDER BY
PostalCode,
StoreName