How do I put an ‘if clause’ in an SQL string?

For your specific query, you can do: UPDATE purchaseOrder SET purchaseOrder_status=”COMPLETED” WHERE purchaseOrder_ID = ‘@purchaseOrder_ID’ and not exists (SELECT * FROM itemsOrdered WHERE purchaseOrder_ID = ‘@purchaseOrdered_ID’ AND status=”PENDING” ) However, I might guess that you are looping at a higher level. To set all such values, try this: UPDATE purchaseOrder SET purchaseOrder_status=”COMPLETED” WHERE not exists … Read more

Left Join With Where Clause

The where clause is filtering away rows where the left join doesn’t succeed. Move it to the join: SELECT `settings`.*, `character_settings`.`value` FROM `settings` LEFT JOIN `character_settings` ON `character_settings`.`setting_id` = `settings`.`id` AND `character_settings`.`character_id` = ‘1’

What is best tool to compare two SQL Server databases (schema and data)? [duplicate]

I use schema and data comparison functionality built into the latest version Microsoft Visual Studio 2015 Community Edition (Free) or Professional / Premium / Ultimate edition. Works like a charm! http://channel9.msdn.com/Events/Visual-Studio/Launch-2013/VS108 Red-Gate’s SQL data comparison tool is my second alternative: (source: spaanjaars.com) http://www.red-gate.com/products/sql-development/sql-compare/ http://www.red-gate.com/products/sql-development/sql-data-compare/

How to see query history in SQL Server Management Studio

[Since this question will likely be closed as a duplicate.] If SQL Server hasn’t been restarted (and the plan hasn’t been evicted, etc.), you may be able to find the query in the plan cache. SELECT t.[text] FROM sys.dm_exec_cached_plans AS p CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t WHERE t.[text] LIKE N’%something unique about your query%’; If … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)