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

Generate a Series of Numbers

I am trying to generate random serial numbers in PostgreSQL with some conditions. The numbers need to start with the same 3 letters, YAK. After YAK, there needs to be 8 random digits. I only need to do 10 iterations of this. I know I should try to start with generate_series() but can I use

Read More
SQL

SQL Server 2008 vs SQL Server 2017 performance issues

I recently had to migrate a database from SQL Server 2008 Express to SQL Server 2017 Express and one of the stored procedures started suffering a very significant performance impact. The profiler shows that on SQL Server 2008 this stored procedure performs 1370 reads and takes 59ms to execute, while on SQL Server 2017 this

Read More
SQL

Splitting a list of numbers into two groups with its best combination possible without splitting a number

I want to split a list of quantities between two groups of peoples without splitting any single quantity. The goal is to split the quantities into two groups using the best combinations possible. Please find below an example: List of quantities: The quantities are in different rows as below. ID Quantities 1 30 2 36

Read More
SQL

Splitting a list of numbers into two groups with it's best combination possible without splitting a number

I want to split a list of quantities between two groups of peoples without splitting any single quantity. The goal is to split the quantities into two groups using the best combinations possible. Please find below an example: List of quantities: The quantities are in different rows as below. ID Quantities 1 30 2 36

Read More
SQL

Problem in query that returns information from Oracle customers by site

My query should have only the records that were modified in sysdate SELECT /*********hz_parties******************/ hp.party_id, hp.party_name, hp.jgzz_fiscal_code, To_char(hp.creation_date, 'DD/MM/YYYY'), /*********hz_party_sites******************/ hps.party_site_id, hps.party_site_number, /*********hz_organization_profiles******************/ hop.attribute2, hop.attribute1, hop.attribute3, /*********hz_locations******************/ hzl.attribute6, hzl.postal_code, hzl.address1, hzl.addr_element_attribute3, hzl.state, hzl.addr_element_attribute2, hzl.city, hzl.attribute1, CASE WHEN hzl.attribute7 IS NULL THEN NULL ELSE (SELECT vst1.description FROM fnd_vs_values_b VSV1, fnd_vs_values_tl VST1 WHERE vsv1.value = hzl.attribute7 AND

Read More
SQL

Is there a way to IGNORE INDEX (PRIMARY) or FORCE INDEX in hql?

I have the below hql query: @Query("SELECT es FROM EmailSubscription es " + "JOIN FETCH es.subscriber s " + "WHERE es.subscriptionTypeId = :typeId " + "AND es.active = :active " + "AND es.id > :batchStartId " + "ORDER BY es.id ASC") @QueryHints(@QueryHint(name = "org.hibernate.fetchSize", value = "1000")) Unfortunately it takes about 2+ seconds to fetch

Read More
SQL

How do I put in a combobox when the DISTINCT is used

I am trying to put in a combobox while using the DISTINCT is use. It works without the DISTICNT < using (SqlConnection conn = new SqlConnection(zGV.csAviation)) { try { string query = "select '<Select>' as name, 0 as id union Select name, id from Airlines ORDER BY Name "; SqlDataAdapter da = new SqlDataAdapter(query, conn);

Read More
SQL

Having count(*)>1 and but ignore duplicate if same key

I used count(*) > 1 but it is showing duplicate rows as well. I want to see only unique rows Table: A id name class key 1 abc 1 ACB3 1 abc 1 ACB3 2 ccd 2 XY4 2 ccd 2 ZZ5 Result expected: id name class key 1 abc 1 ACB3 2 ccd 2

Read More
SQL

Send message to trigger

Is it possible to send a message that can be used in trigger code? Something like CREATE TRIGGER MyTrigger ON MyTable AFTER INSERT AS BEGIN INSERT INTO AnotherTable (Col, TheMessage) SELECT Col, TRIGGER_MESSAGE FROM inserted -- TRIGGER_MESSAGE contains 'Hey, its me' END INSERT INTO MyTable (Col) VALUES (1) TRIGGER_MESSAGE 'Hey, its me' You need to

Read More
SQL

Sum Over Partition duplicate rows

My query to show transaction and receipt amounts by transaction are duplicating the transaction amounts when multiple receipts are applied to it. I’m using select distinct and the sum over partition since a transaction might have multiple lines, and I only want to report the total transaction amount here. select distinct sum (rctl.revenue_amount) over (partition

Read More