Skip to content
Advertisement

Tag: sql-server

Extract all records from a JSON column, using JSON type

I have a couple tables (see reproducible code at the bottom): tbl1_have tbl2_have I wish to extract all json columns without providing explicit data type conversion for each columns since in my use case the names and amounts of nested attributes vary. The expected output is the same for both cases: tbl_want with a_i and a_j correctly stored as a

Create new column and fill all rows with the same field values

I have a database that rates outfits. I want to take the value of predicted rating when predicted month = base month and fill it into rows with the same base month, shirt, pants, and shoes in a new column called actual rating, as shown below. predicted month base month shirt pants shoes predicted rating 4 0 1 1 1

Retrieve the last valid value from a previous date

I have the following table “Rates”: aDate realRate isBusinessDay 01-04-22 1.10 1 02-04-22 1.20 1 03-04-22 1.30 1 04-04-22 1.40 0 05-04-22 1.50 0 06-04-22 1.60 1 07-04-22 1.70 1 08-04-22 1.80 1 09-04-22 1.90 1 10-04-22 2.00 0 11-04-22 2.10 0 12-04-22 2.20 0 13-04-22 2.30 0 14-04-22 2.40 1 15-04-22 2.50 1 16-04-22 2.60 1 17-04-22 2.70 1

Aggregate dynamic columns in SQL Server

I have a narrow table containing unique key and source data Unique_Key System 1 IT 1 ACCOUNTS 1 PAYROLL 2 IT 2 PAYROLL 3 IT 4 HR 5 PAYROLL I want to be able to pick a system as a base – in this case IT – then create a dynamic SQL query where it counts: distinct unique key in

how to get data grouped by ids

I have grouped data in a temporary table according to id_card. There are multiple activities for each card. I want to send 1 email for all activities happened on that particular card. But, I don’t know how to get data according to ids. should i use cursor for fetching the ids ? Example in the table, want 2 rows for

Return list of Students by ZipCode Count

I am trying to get a list of students that live in the same zip code where zip code count > 1. I tried the following and get nothing in my query. If I remove s.Student, I get results of zipcode and count, but I want to include student also. Below are the database tables I am using. Answer I

Advertisement