October 22, 2024
Chicago 12, Melborne City, USA

SQL

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample dat

SQL

Using IIF in SQL update statement – Returns [S0001][207] Invalid column name

I am using IIF in an Update query to set a column in SQL Server table, however I am getting an error "Invalid column name ‘Y’" Here is the query, I want to update a column called PREVIOUS_STATUS to ‘Y’ only if another column DATE_CREATED is not null UPDATE [dbo].[ACCOUNT] SET STATUS = 'ACTIVE' PREVIOUS_STATUS

Read More
SQL

Trigger Execution connection failure in SQL Server Management

Received following notification when trying to run query: Logon failed for login ‘*LOGIN NAME’ due to trigger execution. Changed database context to ‘master’. Changed language setting to us_english. (Microsoft SQL Server, Error: 17892) Thanks I have tried disabling the trigger execution as well as trying DAC login. None of these seem to resolve the issue.

Read More
SQL

Using SQL in an Excel workbooks exhibits strange behavior until the devise is rebooted

I have a macro that runs a a number of different SQL statements. I use the same macro each day. The 1st step is I update the Pending worksheet. The 2nd step is to identify new contracts. New contracts are identified by a SQL statement that compares the Pending worksheet to the History worksheet. Anything

Read More
SQL

How to select rows with atleast one non-zero value in SQL server

I have a table with 20+ columns and some rows would only have 0s for all the column. Is there a way to filter out rows where all the columns have 0? I could use select * from table where CONCAT(col1,col2,col3)!= '000' but I don’t want to write 20+ zeroes in my case and there

Read More
SQL

Aware datetime objects output different UTC offsets in one timezone

My database is storing dates with time in UTC timezone. I have a python program that uses ORM to query database. This ORM is configured to use Europe/London timezone. When I receive python datetime objects I expect them to be in +01:00 offset, but some dates have +00:00 (UTC) offset as can be seen below

Read More
SQL

What's the best way to get grouped data from a table into a JSON object as tree structure

I need to get grouped data from ORACLE table into a JSON object as tree structure Oracle version 19c if that matters The table will be like this: create table a_table ( store varchar2(100), brand varchar2(100), product varchar2(100), quantity number, amount number ); insert into a_table t (store, brand, product, quantity, amount) values ('All Motors

Read More
SQL

Defining the target database with Entity Framework migration script generation

Generating script with Entity Framework requires the script to be run on a specific database. In our setup, we want our database administrators to run the script, but at the same time we want to ensure that the script is not executed on an unintended database. This is easily achieved by starting the script with

Read More
SQL

SQL join with missing data

I have two tables, NAME and ADDRESS. For both tables, the primary key is ID and Language. I want to join these two tables on ID and Language, but sometimes there will be a case where the address table does not have a matching language for the ID, but there is a matching entry with

Read More
SQL

Issue Passing NULL StartDate from Main Report to Subreport in SSRS Body:

I’m working on an SSRS report in Visual Studio that passes parameters between a main report and multiple subreports. The goal is to have parameter values Option1 and Option2 that input StartDate param and enter it based on calculations (those options work fine, they’re implemented in the stored proc that runs on the subreports) but

Read More
SQL

Get back the NULL date records between another set of dates

In MySQL 5.7, I have a table that looks like this: | email | a_last_sent | a_last_open | b_last_sent | b_last_open | ...more columns ---------------------------------------------------------------------------------- | email1 | 2024-06-12 | 2024-06-25 | 2024-03-06 | 2024-06-06 | ---------------------------------------------------------------------------------- | email2 | 2024-06-01 | 2024-06-16 | 2024-06-05 | NULL | ---------------------------------------------------------------------------------- | email3 | 2024-06-01 | NULL

Read More