I reckon you are making that job 10 times harder by doing it as a created string, to then execute. During development I'd just create the appropriate SQL syntax, until it works, then convert it into a string to be executed.So something like:SELECT @xxxVisits = count(sessionid),@CntSession = case when isnumeric(result) = 1 then count(cast(Sessionid as numeric)) ELSE NULL END,@CntSales = case when isnumeric(result) = 1 then count(cast(result as decimal)) ELSE NULL END,@xxxConv = case when isnumeric(result) = 1 then convert(decimal(18,2),(1.0)* @CntSession/@CntSales) else 0.00 end
Kristen