开发者

SQL error in SQL server using REPLACE statement

开发者 https://www.devze.com 2023-04-11 00:25 出处:网络
I have the following query: REPLACE sessions (session_id,session_data,expires) VALUES(\'pcal586o43604g0vpu5j22\', \'id|i:111;user|N;s:9:\\\\\\\"admin\\\\\\\";admin_page|s:16:\\\"/control/\\\";\', 1开

I have the following query:

REPLACE sessions (session_id,session_data,expires) VALUES('pcal586o43604g0vpu5j22', 'id|i:111;user|N;s:9:\\\"admin\\\";admin_page|s:16:\"/control/\";', 1开发者_运维技巧317934461) 

Which works fine with mysql but when using SQL SERVER it throws this error:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'session_id'.

Can anyone tell me anything that might be wrong with this query?


There is no command REPLACE in SQL Server to replace values in a table.... you need to use a standard SQL UPDATE statement instead:

UPDATE dbo.sessions 
SET session_id = 'pcal586o43604g0vpu5j22',
      session_data = 'id|i:111;user|N;s:9:\\\"admin\\\";admin_page|s:16:\"/control/\";',
      expires = 1317934461
WHERE .... (some condition here - otherwise you update ALL rows!)

T-SQL's REPLACE function is a string function to replace a given substring inside another string with a replacement.


SQL Server has no equivalent to MySQL's REPLACE. You'd have to code the functionality manually.


In TSQL, REPLACE is a string function, rather than a set-based operation.

In MySQL, REPLACE is a MySQL extension to the SQL standard. It either inserts, or deletes and inserts.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号