0

I'm trying to run something like this in Excel:

SELECT currency_id, period_id, date, price_1, price_2

FROM Prices

WHERE scenario_id='1' AND period_from='04/14/2014' AND period_to='04/14/2014'
 AND date='04/14/2014' AND date_time='04/14/2014' price_type='r@periodic'

How to escape @ symbol in SQL WHERE Clause?

I got "Incorrect syntax near 'price_type' error.

BP_
  • 2,497
  • 5
  • 18
  • 18
  • Duplicate of : http://stackoverflow.com/questions/258757/escape-a-string-in-sql-server-so-that-it-is-safe-to-use-in-like-expression – sarin Apr 15 '14 at 13:46
  • 1
    Your query shouldn't give you a syntax error, and if it does, then you have an error in another part of your query. So post the full error message and the full query too – Lamak Apr 15 '14 at 13:48
  • If the value you are trying to match has an @ symbol, removing it will cause a zero result set anyway. – durbnpoisn Apr 15 '14 at 13:50
  • 1
    Please show us the complete and exact error message –  Apr 15 '14 at 13:51
  • I'm running this query from Excel. The pop up message I get is 'Incorrect syntax near 'price_type'. – BP_ Apr 15 '14 at 13:53

2 Answers2

2

AND operator was missing between date_time='04/14/2014' and price_type='r@periodic'

BP_
  • 2,497
  • 5
  • 18
  • 18
0
DECLARE @Bit VARCHAR(10) = 'r@period'
select REPLACE(@Bit,'@','')
mohan111
  • 8,633
  • 4
  • 28
  • 55