Using SUM OVER without an Order by
We capture the MPF at a header level and call it TOTAL_MPF.We also capture Line Level MPF and call it MPF.The sum of the Line MPF should equal the TOTAL_MPF. We have some feed issues and a lot of...
View ArticleCTE Group By not grouping results correctly
I have the following CTE that is doing a SUM on the field MERCHANDISE_AMT, seperately from 2 different queries and then I'm joining those results together in the final select. I'm having a problem with...
View ArticleInsert to Clustered Index
Hello, I have a stored procedure that consists of a relatively simple INSERT INTO SELECT, the table being inserted into is a Clustered Index. The target table is truncated before being inserted with...
View ArticleStored Procedure and Output value
Hi,I have created a stored procedure with two outputs. The @RowsUpdated works fine, but I am struggling to get a value for @id_user. I have tried using if EXISTS(SELECT @id_user = id_user from...
View ArticleTable data records comparison based on transaction logs?
Hi, We are having a disaster recovery exercise and I need to validate the accuracy of the records in the backup database server against the production database server. Here's what has been done:1....
View ArticleRetrieve rows where specific columns are different between columns
I have the following SQL (that I got assistance on her with) to obtain both highest (max) and 2nd highest dated rows. There are some cases in the data where the only difference in the 'OLD ROW' and...
View ArticleChange in row values identification
Dear Fellows,How could be find the records where specific values/field changed. In the sample table we need to find those accounts where class has been changed based on date.SQL Code for te
View ArticleGet the distinct records which having same date with different time stamp.
Hi Team,Need some on the below requirement.I have the table and data like below.create table trend(keyinstn INT,ratingdate datetime,rating varchar(10))insert into trend VALUES(4000193,'2009-03-19 02:5
View ArticleLoading Data from Staging Table to Parent and child tables
Hi,I am trying to load data fro mSTaging table (No Primary Key as it's from the csv file) but in Child table and it's inserting all the Parent Kel column value, just picking up last value, see the code...
View ArticleDate Range Consolidation Query
Hi there,I have a table that stores date periods against PersonID's and there should be no overlapping date periods for a given PersonID (a period starting on the same day as another ending is...
View ArticleBCP SQL 2014 Incorrect syntax near the keyword 'in'.
Hello,When I try to run below BCP command from SSMS SQL 2014 version or sqlcmd line[code language="sql"]bcp "[db_name].[dbo].[Table]" in "Q:\Table.txt" -c -T[/code]IT gives me this error,Msg 156
View ArticleSelecting different columns of joined tables based on certain criteria
I wanted to retrieve single rows of two columns based on a certain criteria after joining multiple tables. To explain it with example, I've this: [code language="sql"] SELECT c.colu
View Articlehow to set value of variable = variable + string
In subject line of email I want @Subject to return "'Submission at 10/03/2019 22:46:34". Concatenating with + and quotes isn't working. How is it done?[code language="sql"]DECLARE @
View ArticleSelect latest and 2nd latest date rows per user
I have the following query to select rows where the LAST_UPDATE_DATE field is getting records that have a date value greater than or equal to the last 7 days, which works great.
View ArticleUsing a local Excel file in an SQL Server query
we keep data in an Excel spreadsheet on a local drive.Can i use that data in an SQL query??I do not have permissions to create tables. I thought our previous BI Expert did this.THoughts? We want to...
View Articlewhich way is better for joins? or are both options popular?
i have a question about joining tables. I have read online people describing the two methods below..Method 1 - joining tables in a straight line (see below)Method 2- joining both tables from the first...
View ArticleSELECT and UPDATE Data
Hi All,We have a table which have high data insert with a status flag column , I want to select data having status=1 and then update the status to 2. The table get inserted very frequently and now what...
View Articlesent SQL query as formatted Excel .xlsx via email
I already have a working stored procedure that exports sql query data set into a .csv file and emails it. Works great.Now I need to modify it to send dataset as a formatted .xlsx report! &nb
View ArticleCompare Lists
Hi Everyone,Reaching out for some help solving a SQL problem. I have a list of active servers and a list of packages and which servers they were deployed to. I am trying to return a list of missing...
View Article