October 29, 2018 at 8:16 am
Afternoon all,
Please can anyone help me with a Microsoft SQL Server query?
I have set a constraint against a particular column which only allows the values of 1-100 to be entered.
I would like to write a query against that column which basically says:
'Show me a list of values between 1-100 which are not present within that column'
I have the full scripts to create and populate the database if that helps anyone.
Thanks
October 29, 2018 at 8:27 am
acarmon02 - Monday, October 29, 2018 8:16 AMAfternoon all,
Please can anyone help me with a Microsoft SQL Server query?
I have set a constraint against a particular column which only allows the values of 1-100 to be entered.
I would like to write a query against that column which basically says:
'Show me a list of values between 1-100 which are not present within that column'
I have the full scripts to create and populate the database if that helps anyone.
Thanks
;WITH A(A) AS (SELECT '' FROM (VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) T(C)),
B(N) AS (SELECT TOP(100) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) N FROM A A,A B)
SELECT B.N
FROM B
WHERE NOT EXISTS(SELECT * FROM myTable X WHERE X.myCol = B.N)
October 29, 2018 at 9:56 am
Same Idea as Jonathan's query, I just prefer this for readability (which is subjective :))
Select possibleValue from mydb.dbo.PossibleValuesTable
EXCEPT
select actualValue from mydb.dbo.ActualValuesTable
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
October 29, 2018 at 9:34 pm
Matt Miller (4) - Monday, October 29, 2018 9:56 AMSame Idea as Jonathan's query, I just prefer this for readability (which is subjective :))
Select possibleValue from mydb.dbo.PossibleValuesTable
EXCEPT
select actualValue from mydb.dbo.ActualValuesTable
More of the same idea...
SELECT PossibleValue = N FROM dbo.fnTally(1,100)
EXCEPT
SELECT ActualValue FROM dbo.ActualValueTable
;
Code for dbo.fnTally is attached (heh... seriously? An SQL Server forum that won't allow attachment of files that have a .SQL extension)
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply