Create table for store raw data: Create table for processed data: Now store raw data: I am turning a comma separated string into individual rows: Like this: value 10 2 0 95 15 I want to insert into SplittedAndProcessedData table using a loop, like this: ID count 1 8500 2 8510 3 8512 4 8512 5 8607 6 8622 Which
Tag: tsql
Case statement help for replacing null from multiple joins
so i have the following case below where if jl name does not have n/a i want it to come from the same column. if there is n/a i want to look into this subquery and find the recent jl name. but if the …
If today is friday then extract data 7 to 9 days from today, if not 7 days
If today is Friday, I would like to get data 7 to 9 days from now, if not 7 days. I am using SQL Server. Before: id class startdate 1 English 2020-12-21 00:00:00.000 2 English 2020-12-22 00:00:00.000 3 Math 2020-12-21 00:00:00.000 4 English 2020-12-27 00:00:00.000 5 Math 2020-12-27 00:00:00.000 If today is 14/12/2020 – Monday, it will produce the result
Date Format Convert
I am dealing with sql DB where the date is recorded in this format ‘2020-348T08:55’. I need to convert this to datetime. Please guide if there is possible way to do that? Answer With string and date/time functions extract the year and days to create a DATETIME without the time and finally add the time part: If the days part
I can’t get rows have NULL on all rows for column zfeaturekey based on zplid and code type?
I work with SQL Server 2012. I have an issue I can’t get rows from table #gen when it has Null only on all rows on zfeaturekey field based on zplid and codetypeid. I need to get rows that have NULL only on all rows ON zfeaturekey, but must be same codetypeid and same zplid . Output: This is the
Select only the records with same values
I am working on a SQL statement that will become a part of a view. What I need is to extract only the records that have the same unique key twice. The query looks like below right now. The result I get from the query above is: I need to modify the SQL statement so that the end result is
Add and update a column with sequential numbering based on grouping
I have a table with following structure Id Division Details 1 A some text 2 A some text 3 B some text 4 B some text 5 B some text I need to add a new column of integer type named “Order” with some data as described below: Id Division Details Order 1 A some text 1 2 A some
Insert into a table in another database after first deleting
I have two databases that have same tables on those. First I had to delete all the data in employee_table in Database_1. Then after that I need to insert data in the employee_table in Database_2 to the employee_table in the Database_1. I am using SQL Server Management Studio 2017. Is there any solution for this? Answer You should first insert
Conditional Inner Join with two Functions
I have two functions. I need to decide whether to join with these two based on a BIT Value. Basically if BIT=0 join with function 1 else join with function 2 I tried putting an IF Clause .. but it does not seem to work. What is the proper way to do it? Answer Just add your static condition as
Conversion failed when converting the nvarchar value ‘$28,926.25’ to data type int
Full error message Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the nvarchar value ‘$28,926.25’ to data type int. Answer Something to understand when programming on almost ANY platform is converting between number values like 123.45 and string or text values like “123.45” is a surprisingly slow and expensive operation. They may look the same, but