I have this query below: select Contact.IndividualID, Contact.IndividualID as ContactId, Contact.CaseNumber as CaseID, [Case].ProgramCode as Benefit, Contact.Email as EmailAddress, …
Tag: tsql
Rolling sum based on date (when dates are missing)
You may be aware of rolling the results of an aggregate over a specific number of preceding rows. I.e.: how many hot dogs did I eat over the last 7 days SELECT HotDogCount, DateKey, …
WHERE clause is not filtering all specifications
I’m trying to make a query with different specifications in WHERE clause and some of them are being ignored. SELECT DISTINCT f.NameLawyer AS ‘Comisiona’, f.Bill As ‘Factura’, f.Amount AS ‘…
TSQL filter that I do not understand, 2 versions that I thought would return the same data do not
So I have a SQL statement that was not returning data like it should (MSSQL Server), in part of the query I had this turns out if I changed that to then it returned the data I expected, I would have thought those 2 things would be equivalent but obviously not in TSQL. Here is the full Statement My question
Get all group by values in column a where all values in another column is true
I have a table that looks like this: I wanted to create a query that gives me a group by OrderID and Canbefulfilled but if there is a single 0 in Canbefulfilled column , I want that column to be 0 I …
SQL Syntax – Section in MERGE Statement
It’s been a while since I’ve worked in a T-SQL environment. I previously worked for Google, and, of course, they had their own special flavor of SQL. Now that I’m back, I’m reading back up on my T-SQL features. I understand the MERGE statement (at least, I think I do!), but I was looking at examples, and I saw one
Rows with duplicate column values
I am pretty sure there are rows with duplicate column values in the table: SELECT TenancyReferralKey, FromDate, ToDate, ToDate_Value, ReferralID, ReferralFor, …
How to accurately pull minimum date of each time a payment method was changed
I need to get the minimum date for each time a payment method changes between the method id, account number, or routing number. I’m bouncing between a cursor and between windows functions. Doing the method below seems to work fine, but when i use this method with a larger dataset, with different pay ids involved, it doesn’t seem to be
Count and group data by Year/month and by user
I have a dataset that looks like this: GO CREATE TABLE [dbo].[taskDB]( [ticket] [varchar](50) NULL, [created] [date] NULL, [closed] [date] NULL, [rating] [varchar](50) NULL [user] […
Are SQL Server unique constraints “Silent” or do they raise an exception?
I want to prevent inserting duplicate values into my tables. At first, I added code to check if the value already existed in the database, but that seems like a lot of overhead / wasted time if I can prevent it at the DDL level. So I found this and changed one of my tables (as an example) from this: