I have a select query (Oracle database) with group by clause that needs to return 4 rows if all required data exist. It works perfectly. How can I write a select query that returns same 4 rows even if …
Tag: sql
Receiving this error: The multi-part identifier “c.hrmort” could not be bound
All solutions point to the fact that if I’ve assigned aliases in my code, I should be using them instead of the table name itself. I have assigned alias and I AM trying to use the alias, however, I am still receiving this error. Does this have to do with using an left join? My code is as follows: Answer
How to exclude a specific row from an SQL Count
I need to exclude a certain row from a COUNT in SQL Server. This is what I have: If I remove the last AND GuestStayDetails.GuestId != @GuestId; it gives me the expected COUNT however I must exclude one of the GuestIDs. Any suggestions? Answer It looks like you are looking for overlapping time intervals —…
SQL if parameter is empty string query entire DB else query only last 10 days
I have a query for the last 10 days. I also have a variable declared. If the variable is empty string I want to query the last 10 days (works fine). If the variable string is not empty I want to search all rows not just the last 10 days. I cannot put an if condition around the WHERE clause.
SQL Server 2008 R2 split one row of results into two rows
In simple terms the table (t1) looks like this: I’d like to get results from the table that looks like this: Thanks Answer You may try simple query, using operator Union:
Sort by year as nvarchar and then numerically
I have an nvarchar column that in essence stores the following data: The first two numbers represent the year created and the last numbers represent the id of the unit made that year. Whenever I sort I get the 99’s first and 19 last. I’d like to sort by latest year first and then numerically. I ha…
Can this be done as a SQL VIEW
I have a SQL Server table of Customer’s Events: There can be many EventTypes for the same customer in one day. EventTypes are like 1 – CheckIn 2 – CheckOut 3 – ExamStart 4 – ExamEnd Now I want to select Customers that are currently (today) on premises. That’s Clients who ha…
Can I SELECT all the bult-in functions in SQL Server?
Is it possible to display every built-in function (like LEFT, SIN, IIF etc.) with a query? Answer Documentation or syntax highlighting definition from official tool: Azure Data Studio – syntax support Searching for: “name”: “support.function Idea – Not tested: Maybe it is possibl…
Is there a way to look at the previous evaluation within a CASE expression?
I’ve created the following table in Excel as an example. I would like to do a similar expression (like the formula shown in Excel) in SQL Server on a similar looking table. The columns row_num and switch were already created based on previous CASE statements. Click for Excel sheet Is there any way to ac…
Calculate sum of duration SQL
I use the following sql to calculate the duration in the first query. CDate(TimeSerial(Val([EndTime])100,Val([EndTime]) Mod 100,0)-TimeSerial(Val([StartTime])100,Val([StartTime]) Mod 100,0))) AS …