I have a data type problem and I need to use an SQL Replace to tidy up my only the quotes/apostrophes are driving me nuts:
I have a data value PR.Type which is a string value of the form 1, 2, 3
And I need to test if a numeric value (ie: 1) is in this string
SELECT firstname, surname, email
FROM clients as C INNER JOIN propertyrequirements as PR
ON C.clientid = PR.clientid
WHERE 1 IN (PR.type)
Yields a datatype mismatch. I need to adjust my WHERE clause so the values I’m comparing are of the same datatype to do this I need to
(a) wrap the ‘1’ in single quotes and (b) adjust the data in the PR.Type field so each of the comma separated values are also enclosed in single quotes.
I was hoping to be able to do this with a Replace function, but I’m getting know where fast and suffering from quote confusion.
Here’s where I’ve got to:
SELECT firstname, surname, email
FROM clients as C INNER JOIN propertyrequirements as PR
ON C.clientid = PR.clientid
WHERE '1' IN (''' & Replace(PR.type,',', '', '' ) & ''')
Am I going about this the right way? Have just got in a quoted mess?
Thanks for your help, but you are right this isn’t going to scale, I have several other values I need to compare in the same WHERE clause all using similar comma separated ids. If I normalised the database would this allow the query to scale?
In other words, just the kind of things I’ve been trying to do.
Its a pig really, I’d have never designed this database this way. The developer who had this before me obviously saw the merits of just taking a comma separated list of field values and dumping them into the insert and update routine writing the Property Requirements values into a single table. But now I’m been asked to do something useful with this data its proving a proper pain in the butt.