Skip to main content
7 votes

Variable SQL join operator using case statement

CASE is not a statement, it returns a value expression, so it's not going to work in a situation where you need a logic boolean result. You can just use OR instead SELECT * FROM SickLeave lv INNER ...
Charlieface's user avatar
  • 14.5k
4 votes

Deleting multiples that aren't exact PostgreSQL

From the description it seems that you are trying to fix the data. In your case id should be PRIMARY KEY, and the year column UNIQUE. If you just want to select the data use, WITH distinctYears AS ( ...
Ergest Basha's user avatar
  • 4,463
4 votes

Guarantee SQL Management Studio Query

Sounds to me like you (and Change Management) are concerned about people running SQL directly in your [Production] databases and making changes to the wrong database. Management Studio cannot directly ...
Phill  W.'s user avatar
  • 9,480
2 votes

Guarantee SQL Management Studio Query

It's a little unclear what you're asking but let me do my best to address each of your questions: When running a query in SQL Server Management Studio, is it then possible to guarantee that the ...
J.D.'s user avatar
  • 39.5k
2 votes

Deleting multiples that aren't exact PostgreSQL

It's not clear what the actual rule should be, but if is that year must be id+1999 then: DELETE FROM tablename WHERE year <> id+1999 would be more than enough (but then one wonders why you have ...
jcaron's user avatar
  • 572
1 vote
Accepted

Variable SQL join operator using case statement

Case returns a value expression, but that does not mean that it cannot be used in this case. Just need to have it return a value than is then used in a comparison, as this: SELECT * FROM SickLeave ...
Mário Pereira's user avatar
1 vote
Accepted

Sql Server: Query to parse and validate codes

One relational way you can do this is by splitting your #SourceData first (fortunately you have access to the STRING_SPLIT() function despite being on an outdated version of SQL Server), then getting ...
J.D.'s user avatar
  • 39.5k
1 vote

Sql Server: Query to parse and validate codes

-- first thing that comes to mind: SELECT sd.ID , sd.Codes , CASE WHEN NOT EXISTS ( SELECT x.[value] FROM string_split(sd.Codes, ';') as x ...
Doug Hills's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible