pls take a look at my query:Declare @allowAll bitSet @sql = 'Select @allowAll = CD.blnAllowAll from CodeDpndCol2 CD inner join CodePFMulti2 CP on CD.lngCodeSourceID = CP.lngCodeID inner join Element' + @acctLevel + '_Codes EC on EC.lngIndex = CD.lngCodeDependID where CP.lngProfID = ' + @profID + ' and EC.txtCostCenter = ' + @array_value
I have to make this dynamic because one of the tables (Element#_Codes) I'm joining is got to be dynamic. I then use the value of @allowAll in my query somewhere. When I run this query, I get the error "@allowAll must be declared" but it is declared. If I change the query to look like this:Declare @allowAll bitSet @sql = 'Select ' + @allowAll ' + = CD.blnAllowAll from CodeDpndCol2 CD inner join CodePFMulti2 CP on CD.lngCodeSourceID = CP.lngCodeID inner join Element' + @acctLevel + '_Codes EC on EC.lngIndex = CD.lngCodeDependID where CP.lngProfID = ' + @profID + ' and EC.txtCostCenter = ' + @array_value
I get the error "Invalid operator for data type. Operator equals add, type equals bit." What's the best way of writing this dynamic query? Help pls. (I previewed this post and it seems the '+' character before and after the variables are not being shown. There are '+' chars before and after the variables.)