Skip to content
Advertisement

Tag: tsql

How to split string with delimiter and get the first value

I have the following query where I have a table which is storing from information with a delimiter SQL version – Microsoft SQL Azure (RTM) – 12.0.2000.8 Getting the following results Where I need the results to be Answer If you only interested in the first value, you don’t need to use STRING_SPLIT(). You can simply use charindex() to find

How to add a query to a table in SQL?

I have 3 tables. For simplicity I changed them to these sample tables. table1: CorporateActionSmmary table2# ProductMaster table3# OpenPosition First I need to add ISIN from table2 to table1 table1: CorporateActionSmmary So, I used this code Now as you can see the Quantity is missing in Table1 so I have to add-up all the quantities in Table3 for each product

How to avoid rerunning a subquery used multiple times?

The following is a simplified example of a problem I’m running into. Assume I have a query “SomeQuery” (SELECT… FROM… WHERE…) that gives an output that looks like this: Status MyDate A 6/14/2021 A 6/12/2021 B 6/10/2021 A 6/8/2021 B 6/6/2021 A 6/4/2021 I need to get the earliest status A date that is greater than the maximum status B

Calculating percentages in SQL query

I have a table in SQL that has two columns of data, first is a week number, second is a value. There can be multiple records for the same week. Here’s some sample data (I added some SQL for this data at the end): id WeekNo MyAmount 1 1 5200.00 2 1 180.00 3 1 100.00 4 2 100.00 5

Why does this query return all the rows?

I have the following code: I want to get all the students who have a min grade 6, and I need to do it in subquery in where (most wanted to do it with exists, but not obligatory). My query right now returns all the students, however subquery gets not all of them. Answer If just one grade satisfies the

Advertisement