SQL Server FOR EACH Loop

SQL is primarily a set-orientated language – it’s generally a bad idea to use a loop in it. In this case, a similar result could be achieved using a recursive CTE:

CREATE VIEW must be the only statement in the batch

Just as the error says, the CREATE VIEW statement needs to be the only statement in the query batch. You have two option in this scenario, depending on the functionality you want to achieve: Place the CREATE VIEW query at the beginningCREATE VIEW showing as select tradename, unitprice, GenericFlag from Medicine; with ExpAndCheapMedicine(MostMoney, MinMoney) as ( select max(unitprice), min(unitprice) … Read more

When to use SELECT … FOR UPDATE?

The only portable way to achieve consistency between rooms and tags and making sure rooms are never returned after they had been deleted is locking them with SELECT FOR UPDATE. However in some systems locking is a side effect of concurrency control, and you achieve the same results without specifying FOR UPDATE explicitly. To solve this problem, Thread … Read more

Cannot Connect to Server – A network-related or instance-specific error

I get the following error when trying to connect to SQL Server: Cannot connect to 108.163.224.173. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. … Read more

Why does NULL = NULL evaluate to false in SQL server

Think of the null as “unknown” in that case (or “does not exist”). In either of those cases, you can’t say that they are equal, because you don’t know the value of either of them. So, null=null evaluates to not true (false or null, depending on your system), because you don’t know the values to … Read more

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