I have a very simple data structure with just 3 tables: requests employees teams Basically, what I need is to concatenate 2 different SQL selects into one (so that the query could return just one row). If there’s an employee associated with a request, then return their name (title) and concatenate it wi…
Tag: sql
How to get output parameter and also a table when executing a stored procedure
Scenario I’m working with SQL Server 2017 (not possible to change) I’m using Visual Studio 2019 in C# console and .NET Framework 4.5 (possible to change) I’m using ADO.NET because several years before we couldn’t use Entity Framework, as the system is made to work with a stored procedu…
SQL query based on column condition
I have a sql table in which below are the columns. I’m using sql server. Id, name, device and information on if device is active or not. Need to have a SQL query for below scenario: I want to display firstdevice, seconddevice columns below based on isActive column. If isACTIVE is 1 then, fill the device…
Make table out of different columns and assign values to add them up
I want this: where a win equals 3 points, a win in PV equals 2 points and a lose in PV equals to 1 point, to show like this: I just can’t figure out how to connect the values with SQL-Statements! Any help is appreciated 🙂 Answer You can do: Alternatively, you can filter out rows first and aggregate at…
Trying to extract data form SQL using PS script
I have been trying to get a PS script to work in extracting files (pdf, word, etc.) from an SQL Server database. I came across the PowerShell script below. The script runs and populates the destination folder but all files are 0 bytes and during the script execution. It throws the error: “Exporting Obje…
Upsert (merge) for updating record if it exists and inserting otherwise
I am trying to write a DB2 query that allows me to either update a record if it already exists but if it does not exist it should be inserted. I wrote the following query that should accomplish this: This query should attempt to check if a record already exists for the selection criteria. Updating a record se…
Unnecessary blank row in SQL query
Aim was to write a SQL query to return ride details from a public database. While going through a data analytics course, I stumbled across this problem. the code used is correct as the instruction provided was the same however the result I obtained was different. The first row returned a blank row with just t…
SQL select of records from table A but not in table B
Please, can someone help me find the SQL statement that select all records in TABLE_A except those whose combination of FIELD_1, FIELD_2 is not present in TABLE_B. (In DB2) Answer You can simply use NOT EXISTS:
Querying JSON in POSTGRESQL returns NONE everytime
jsonb column text_results contains values in the following form : {‘Name’ : ‘john doe’ , ‘id’ : ‘123’} On querying Select text_results->>’Name’ as Name from user_master or Select json_extract_path_text(text_results::json,’Name’) as …
MYSQL – Cannot update a parent row: a foreign key constraint fails
db-fiddle link SCHEMA QUERY UPDATE QUERY ERROR If I change the ID of FIELD_TEST, To change the GRAPH_FIELD_INFO_TEST ID referring to the ID of FIELD_TEST, I set it as cascade in GRAPH_FIELD_INFO_TEST. However, it fails due to the following error. If I change the ID of GRAPH, it works normally, but it doesn…