I have a SQL query that runs perfectly under MS SQL Query Analyzer, but will not run in CF. I normally limit CF to simple select, insert, update queries, but this is quite an important component on a project.
The labels coming out should be 1 2 3 etc
Can anyone tell me why this isn't running. Does CF not understand print variables? I would be extremely grateful for any assistance.
Thanks
<CFQUERY datasource="AlexanderForbes" name="list">
declare @add_column int
declare @column varchar(160)
declare @strSQL varchar(300)
declare @search_arg varchar(40)
select @column = uniquekey from matterparties where uniquekey = '46025'
set @add_column = 0
set @strSQL = 'select ''' + @column + '''as '+ '''' + cast(@add_column as varchar(4)) + ''''
select @column
print @strSQL
select @column = rtrim(title+' '+left(contactfirst,1)+' '+contactlast) from matterparties where uniquekey = '46025'
set @add_column = case when @column = '' or @column is Null then @add_column else @add_column + 1 end
set @strSQL = case when @column = '' or @column is Null then @strSQL else @strSQL + ', ''' + @column + '''' + ' as ''' + cast(@add_column as varchar(4)) + '''' end
print @strSQL
select @column = rtrim(jobtitle) from matterparties where uniquekey = '46025'
set @add_column = case when @column = '' or @column is Null then @add_column else @add_column + 1 end
set @strSQL = case when @column = '' or @column is Null then @strSQL else @strSQL + ', ''' + @column + '''' + ' as ''' + cast(@add_column as varchar(4)) + '''' end
print @strSQL
exec(@strSQL)
</CFQUERY>
<CFOUTPUT QUERY="list">
<HTML>
<BODY bgcolor="white">
<table border="1" width="99%">
<TR>
<td width="30%">#1#</td><td width="15%">#2#</td
</tr>
</table>
</body>
</html>
</cfoutput>
The labels coming out should be 1 2 3 etc
Can anyone tell me why this isn't running. Does CF not understand print variables? I would be extremely grateful for any assistance.
Thanks
<CFQUERY datasource="AlexanderForbes" name="list">
declare @add_column int
declare @column varchar(160)
declare @strSQL varchar(300)
declare @search_arg varchar(40)
select @column = uniquekey from matterparties where uniquekey = '46025'
set @add_column = 0
set @strSQL = 'select ''' + @column + '''as '+ '''' + cast(@add_column as varchar(4)) + ''''
select @column
print @strSQL
select @column = rtrim(title+' '+left(contactfirst,1)+' '+contactlast) from matterparties where uniquekey = '46025'
set @add_column = case when @column = '' or @column is Null then @add_column else @add_column + 1 end
set @strSQL = case when @column = '' or @column is Null then @strSQL else @strSQL + ', ''' + @column + '''' + ' as ''' + cast(@add_column as varchar(4)) + '''' end
print @strSQL
select @column = rtrim(jobtitle) from matterparties where uniquekey = '46025'
set @add_column = case when @column = '' or @column is Null then @add_column else @add_column + 1 end
set @strSQL = case when @column = '' or @column is Null then @strSQL else @strSQL + ', ''' + @column + '''' + ' as ''' + cast(@add_column as varchar(4)) + '''' end
print @strSQL
exec(@strSQL)
</CFQUERY>
<CFOUTPUT QUERY="list">
<HTML>
<BODY bgcolor="white">
<table border="1" width="99%">
<TR>
<td width="30%">#1#</td><td width="15%">#2#</td
</tr>
</table>
</body>
</html>
</cfoutput>