Monday 20 November 2017

SQL Server 2008 error - Incorrect syntax near '%'. [SQLSTATE 42000] (Error 102). The step failed

I have a SQL query that fails with the above error when
used in a SQL job designed to email the query results. The syntax is fine when running a
normal query.



I see that other people have had
this issue when using non-standard characters in server names, but my issue is with the
% signs in my query I think and the other solutions don't work for me
:



EXEC
msdb.dbo.sp_send_dbmail
@profile_name =
'SQL-Server',

@recipients = 'XXXXX',
@subject = 'Missing
Essence File Check',
@query = N'SELECT * FROM
([omnibus].[dbo].[OmniBus_CLP_Clips] CLP
inner join
[omnibus].[dbo].[OmniBus_CLD_ClipDetails] CLD on CLP.FLE_ID = CLD.FLE_ID)

inner join [omnibus].[dbo].[OmniBus_FLE_Files] fle on clp.FLE_ID =
fle.fle_id
where CLD_user_data like '%.mov%'
and CLD_user_data not
like '%.m2v%'
and CLD_user_data not like '%.wav%'
and
fle.FLE_file_deleted = 0;',
@attach_query_result_as_file =
1,

@query_attachment_filename = 'Missing Essence File
Check.txt'


Can anyone
advise on how to overcome this error?



Thanks,



Rob

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...