November 10, 2017 at 1:18 pm
I have two tables tblData2017 and tblData2018 that I want to see thedifferences from the two tables. If thedata from the two tables are different I want to list the data from Data2017and the new data from Data2018 in one row. The column was show “Previous Value” and “New Value”. The previous value being from tblData2017 andthe changed value being from tblData2018.
Example:
PreviousValue NewValue
JY100 JY101
My Query:
Select n.fvalue as NewValue
From tblData2018 as n – new
EXCEPT
SELECT p.fvalue as PreviousValue
FROM tblData2017 as p – previous
This query is only giving me the NewValue and not the side-by-side previous and new.
Thanks for your help!
Danie8
November 10, 2017 at 1:21 pm
Danie8 - Friday, November 10, 2017 1:18 PMI have two tables tblData2017 and tblData2018 that I want to see thedifferences from the two tables. If thedata from the two tables are different I want to list the data from Data2017and the new data from Data2018 in one row. The column was show “Previous Value†and “New Valueâ€. The previous value being from tblData2017 andthe changed value being from tblData2018.
Example:
PreviousValue NewValue
JY100 JY101
My Query:
Select n.fvalue as NewValue
From tblData2018 as n – new
EXCEPT
SELECT p.fvalue as PreviousValue
FROM tblData2017 as p – previous
This query is only giving me the NewValue and not the side-by-side previous and new.
Thanks for your help!
Danie8
What column or columns should be used to match the rows in one table against the rows in the other?
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
November 10, 2017 at 1:29 pm
Danie8 - Friday, November 10, 2017 1:18 PMI have two tables tblData2017 and tblData2018 that I want to see thedifferences from the two tables. If thedata from the two tables are different I want to list the data from Data2017and the new data from Data2018 in one row. The column was show “Previous Value†and “New Valueâ€. The previous value being from tblData2017 andthe changed value being from tblData2018.
Example:
PreviousValue NewValue
JY100 JY101
My Query:
Select n.fvalue as NewValue
From tblData2018 as n – new
EXCEPT
SELECT p.fvalue as PreviousValue
FROM tblData2017 as p – previous
This query is only giving me the NewValue and not the side-by-side previous and new.
Thanks for your help!
Danie8
If you want this as a single row you would typically use a JOIN. The EXCEPT keyword is used to pull data from the first query where that data does not exist in the second query which is not at all what you are describing you want.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 10, 2017 at 1:30 pm
You haven't given us nearly enough information to provide you a meaningful solution. Please provide table definitions, sample data, and expected results. Follow the first link in my signature to learn how.
The following code will provide the desired results, but is a total kludge.SELECT 'JY100' AS PreviousValue, 'JY101' AS NewValue
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 10, 2017 at 1:45 pm
Thank you for your feedback and the link on how to post. I'll do more research. Consider this item closed.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply