Group Select in an Only row

SELECT loadNumber, CASE WHEN E.Clave = ‘LOD’ THEN FechaEvento ELSE NULL END AS ‘Load Date USA’, CASE WHEN E.Clave = ‘DAA’ THEN FechaEvento ELSE NULL END AS ‘Colocacion AA’, CASE WHEN E.CLAVE = ‘RPD’ THEN FechaEvento ELSE NULL END AS ‘Docs Listos’, CASE WHEN E.Clave = ‘IDT’ THEN FechaEvento ELSE NULL END AS ‘Llegada MX’,… Read More Group Select in an Only row

If a multi row account has a row in a specified date range, how to select all previous rows for that account before that date?

Say I have a table that looks like the following: Account Sale Date A $5 2023-Jan-01 A $8 2023-Feb-15 B $2 2023-Mar-03 A $7 2023-Apr-10 A $9 2024-Jan-01 If a user selects a date range of 2023-Apr-01 to 2023-Apr-30 I would want the table to filter down to the below: Account Sale Date A $5… Read More If a multi row account has a row in a specified date range, how to select all previous rows for that account before that date?

Why Image inserts different value in bytes

I have a table with a column of type Image and I’m trying to insert the value in bytes using a SQL query like this: INSERT Into DocumentImage (FileName, DocImage, DateTimeAdded) VALUES (‘TestTemp.xlsx’, ‘0x504B030414000600080000002100ECC0AA13A901000035070000130008025B436F6E74656E745F54797065735D2E786D6C20A2040228A0000200000000’, GETDATE()) But after inserting the Image value changes to some other bytes like this ‘0x30783530344230333034313430303036303’ Any idea why this is happening… Read More Why Image inserts different value in bytes

Updating Table After Left Join

Simple reprex below: drop table if exists my_table; create table my_table ( ref int, customer_name char(50) ); insert into my_table(ref, customer_name) values (1001, ‘Alan’), (1002, ‘Bob’), (1003, ‘Christine’), (1004, ‘David’), (1005, ‘Elizabeth’); drop table if exists lookups; create table lookups ( ref int, gender char(6) ); insert into lookups(ref, gender) values (1001, ‘male’), (1002, ‘male’),… Read More Updating Table After Left Join

Multiple Selects to update tblItems – INNER JOIN required?

I need to update the buyersAccountID in tblITEMS with the accountID of a winner who’s boxNo in tblEntrants matches ‘winner’ in tblItems: TBLENTRANTS fileID boxNo accountID TBLITEMS fileID buyersAccountID winner So to clarify: If ‘winner’ which is an integer in tblItems matches the integer boxNo in tblEntrants then I need to store tblEntrants.accountID in tblItems.buyersAccountID… Read More Multiple Selects to update tblItems – INNER JOIN required?

MSSQL – Violation of UNIQUE KEY constraint

I’m getting this error message IntegrityError: (2627, b"Violation of UNIQUE KEY constraint ‘XXXXX_TypeOfData_input_un’. Cannot insert duplicate key in object ‘XXXXX.TypeOfData_input’. The duplicate key value is (Processing Data, Processing Data Name).DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\n") How to add unique constraint when insert? My code INSERT INTO… Read More MSSQL – Violation of UNIQUE KEY constraint