In my application I use multi tenant design in my SQL Server database. My question is: what if one of my customer comes and say, I want my own data as a backup file, how can I create backup file for just that tenant? Is there is any way to do that? Do I need any 3rd party tool? Can
Tag: sql-server
How to Exclude Record Based on Multiple Fields where Records May Share Values
I have two tables of addresses. They are formatted very similarly, to [main] table also has the customer name The shipto table has many addresses for each main customer, and many times the main addresses is also listed as a shipto. I do not want to include that main address in my results but I can’t get it to work
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
SQL Get count of each item within a SQL query
I have this table ID PhoneID PhoneName Active Status 1 1 a 1 1 2 1 b 0 2 3 2 c 1 1 4 2 d 1 1 5 2 e 0 3 6 3 f 1 1 7 3 g 1 1 8 3 h 1 1 9 4 i 0 4 10 4 j 1 1 And
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
Consolidating an SQL UPDATE statement using same table and multiple variables and WHERE IN clause
I have a single table table1 where I am trying to update one column completed to certain values based on id. Because the table remains the same as well as the updated column and WHERE clause field, I have been looking into the potential of consolidating the SQL statements. I have a table1 like this: Here is an example of