Skip to content

R passing SQL results to sql statement

I am pulling some results from MySQL database like below: GetJobCodes=paste0(“select EMPLID from jobCurrent where JOBCODE=’”,JOBCODE,”‘”) JOBCODES = dbGetQuery(connection,GetJobCodes) and I want …

Ordering an alias column in union query

I have a SQL query that utilises a union a few times, and within it I’ve created an alias column called ‘Category’. When I try a simple order by on the alias column it works fine. However the data in my alias column has numbers and they order like 1,10,11 instead of 1,2,3 etc.. When I try ch…

Comparing SQL datetime to C# DateTime.Now

I’ve been trying to find a proper solution for the following problem. I have an SQL table with a time column (in this format: hh:mm:ss). It contains a starting time for a program. I now want to …

Computed boolean column while creating table

I’m trying to create table with computed boolean values CREATE TABLE parts ( Id SERIAL PRIMARY KEY, Weight INTEGER NOT NULL CHECK(Weight > 0), Color VARCHAR(10), Price INTEGER NOT …

NULL handling enhancement in PL/SQL query

The below query doesn’t list out all records that contain null value in WFD_DETECTION_EPA when we pass in some value in S1_WFD_OPERATION_CODE variable. Only records with WFD_DETECTION_EPA is not null …

Rewrite MS Access SQL statement to SQL Server

I wish to convert the following MS Access SQL statement to SQL Server. All of my attempts are resulting in different results from the old & original data. The new Query is: The problem caused by grouping date column in new statement, but in old one it is used in Last function to avoid grouping it and stil…

JSONB sort aggregation

I found this query that suits my needs thanks to this answer here in order to sort fields of data in a JSON document. (Fake, generated random data) SELECT jsonb_agg(elem) FROM ( SELECT * FROM …

Where clause in upsert conflict target

Suppose I have a table created like this: When attempting to insert a new row, there are three possibilties: No row for ‘name’ exists. The new row should be inserted. A row for ‘name’ exists that has a value of NULL. The existing row should be updated with the new value. A row for &#82…