I am trying to get a list of new products. For that, I should look at the date they had movement. If the movement was in 2022, I consider it as new, but if the movement is before 2022, it is no longer new. If i’m set as a condition that the date of the movement be greater than 2022,
Tag: sql-server
Can I use a CTE to make these two tables become one?
Is there any way I can make these two queries become one query? I need all of this to be in one table. Currently I’m not using any common table expression and I believe if I use them I can make these two codes into one single table. I would also like a column called ‘G’ which is a sum
Few issues Inserting and filtering XML data to SQL
I’m having a few issues when inserting data from a XML file to a SQL Server database. How can I get the file name dynamically? This file is put on that path with a different number every time but always starts with Idoc and it’s a .xml file. I’m having troubles setting a variable inside OPENROWSET. At the moment I’m
Correct database after backup
I need some help with a query. Actually we have some wrongs DATA in our database. For some technical reason I restore the backup in another schema. So actually in my Schema1.DB1.TBL1 I got the backed up DATA and in my Schema2.DB2.TBL2 I have the same table but with some wrongs DATA. Could you please tell me an SQL query
Re-format table, placing multiple column headers as rows
I have a table of fishing catches, showing number of fish and total kg, for all the fishing days. Current format of the data is showing as below In the other reference table is a list of all the official fish species with codes and names. How can I re-format the first table so the rows are repeated for each
Using new columns created from PARSENAME
I have split the column PointName using PARSENAME and created 2 new columns and I am needing now to use a WHERE clause to only pull the data for those 6 types. Is there a way to do this? Answer Filling in the blanks a bit, but I would guess you could move the PARSENAME to the FROM and then
SQLServer – Is it possible to divide the results of the same column?
I have a table containing the input and output parameters of different APIs. Here is the structure of my database : The only way to differentiate if a parameter is input or output is the type. If the type is NULL ? It is an output parameter. So, I would like to know if it is possible in a simple
Microsoft SQL Server Streak Counter
I have data in the following format: ID Period Date 1 1 2020-09-05 1 2 2020-10-01 1 3 2020-10-30 2 2 2020-10-01 2 4 2020-12-05 2 6 2021-02-05 3 1 2020-09-05 I want to calculate a streak grouping by both ID and period. The first date instance for each group should start at one, and if the date in the
How to get NULL or Zero values in SQL Server results set
Trying to get the output of all mentioned accounts(total of 9) even though there are no existing records for the GB.periode = 11 Tried using ISNULL(SUM(GB.bdr_val), 0) but still I’m only getting output for GB.reknr = 5210 OR GB.reknr = 5211 OR GB.reknr = 5250 OR GB.reknr = 5340. I have a sample DB layout below, I still need the
SQL Server 2017 STRING_AGG Order By
I’m using SQL Server 2017 Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) – 14.0.2037.2 (X64) Nov 2 2020 19:19:59 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19042: ). I’m trying to sort the results of the STRING_AGG function. This works fine This gives me the error “Msg 102, Level 15, State 1, Line 1