Skip to content

Count the number of results in a seperated list

I know I could probably just count the commas but I wanted to know if theres a built in way to count the results in a comma seperated list? e.g DECLARE @IDs NVARCHAR(100) SET @IDS = ‘2,3,54,234,’ …

Using regex in Oracle sql

I want to extract 2 parts of certain string. For this I want to use regular expressions. For Example the String is: Big_Dog_0044_0080 and my Regex is: Big_Dog_([0-9]+)_?([0-9A-Z]*) Group 1 would be …

How to get count(percentage) for columns after each groupby item?

I have the following table. Using sqlite DB Item Result A Pass B Pass A Fail B Fail I want to realize the above table as below using some query. Item Total Accept Reject A 2 1(50%) 1(50%) B 2 1(50%) 1(50%) How should I construct this query? Answer You can try PIVOT() if your DBMS supports. Then use CONCAT

count business days in calculation

Continuing from my previous question: case when date column is greater than sysdate then ‘Y’ One thing I forgot to consider was including working days in the calculation. Here is the query: So I need to exclude Saturday and Sunday in the calculation above. I tried to add this in the where clause: …

find the max for each value in SQL

i have tables like this table 1 table 2 i want to get the max value for each element in table1 from table2 and the different parameter so the expecited tabel should be like this Answer You can try to compute all the maximums: and then join them with the original Table2, e.g.

Selecting the maximum date before a certain year

I have a table where I’d like to select only the record with the maximum date: The issue is that I have some IDs in the table where the maximum date is in 2022, so that is what gets selected. How do I select the maximum date for a record that is before 01JAN2022 so that my output look like

Before/After Difference for a flexible Date (Case)

i have a little problem with a case. I output two date fields (yyyy-mm-dd). the date changes and is flexible. not every entry has the same date fields. I take one date field as an fixed point. If the Date is 4 months before the date, a ‘V’ should be the output. if it is behind it, an ‘N&#821…

Validation trigger not working in SQL Server

I am working on a trigger for a class project. I have a table named salesman with a column named type. All employees in the table currently have a type of full, part or temp. The purpose of the trigger is to check a newly inserted row’s type and make sure that it matches one of the three that already