Skip to content
Advertisement

Tag: tsql

Getting the primacy function for an emolyee

I have this following query to get the primacy for an employee : My output is like below : What I want is to get primacy (primary,secondary, tertiary) to each function like below : The function having the minimal sumOrder will be the primary function and so on. Answer You can use a ROW_NUMBER() ordered by the SUM() result, then

Update column with below query?

How do I write this query to update a column based on the case statement? Answer As commented, you query looks pretty good, apart from these: the ORDER BY clause does not make sense; an UPDATE query does not return any record, so ordering is out of scope for the same reason, you don’t have to alias the updated column

Query works on SQLite but fails on SQL Server

The following query works for me in SQLite. But in SQL Server, it gives me an error. Invalid column name ‘VehId’. And the editor puts a red squiggly line under the last VehId (but not the first). As you might expect, Vehicles.Id is the primary key. I’m trying to find all foreign keys in Transactions that don’t reference any row

Merge groups of consecutive rows in T-SQL and sum values from each group

Updated 10/08/2019: @Gordon Linoff: I have tried to applied your solution but I realized that is not working as expected. I have added an example with expected result with comments here (https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=1b486476d6aeab25997f25e66ee455e9) and I would be grateful if you could help me. — I have a table of transactions with schema: Here are some row examples: What I want is

Regular expression blacklist

Can someone explain to me the meaning of the following query: SELECT message.message FROM message CROSS JOIN Blacklist WHERE(message.message LIKE {fn CONCAT({fn CONCAT(‘%’, Blacklist.Words)}, ‘%…

Advertisement