I want to pass 'H18E142' as a string in a stored procedure. This parameter will then be used in a dynamic SQL select statement but I have an error saying 'H18E142' is an Invalid column name.
I've placed 'H18E142' within the SQL code directly and it works but when I pass as an absolute valued directly in the dynamic SQL
-- This is the select statement -- The char(7) value being passed in variable @EIRCODE is 'A63DH00'
SELECT ''' + @quarterForDbName + ''' AS Quarter, ADDR_LINE_1, ADDR_LINE_2, ADDR_LINE_3, ADDR_LINE_4 FROM EDB_'+ @quarterForDbName +'.dbo.POSTAL_ADDRESS PA WHERE PA.EIRCODE = ' + @EIRCODE
The expected results returned are the following fields populated for whatever postcode is passed:
-Current quarter -Address line 1 -Address line 2 -Address line 3 -Address line 4