I have put down below a query to retrieve from four tables which are Query: The query is working well but if the Expense table has no values Expense.Invoice_No does not match with Sales_Invoice.Invoice_No, then the query above will return empty rows. But what I wish to do is that, if Expense.Invoice_No does n…
Tag: sql-server
Swap value between rows
I want to swap dynamically values in column VAL2. The case is when in tech I have got X. I want to upload data from other rows where values in cells are the same ( the only difference is EN1 and EN2 ) because values there are reversed. ~~ SQL server I tried to update, case, but I do not
SQL Query results into a already created table
I need some help getting the results from this query: To go into a table I have already created (Routegen). Routegen already has the columns (RouteNumber, DPS, Flats, Parcels). I’ve tried using SELECT INTO, but apparently I’m not doing it right because I can’t get the code to run after chang…
How to I use the LIKE operator?
I’m doing a query using the LIKE operator, but it doesn’t work. When I run the query, there’s no results, but it says “Query executed successfully”. Does anyone know why? This is what I have …
How to select rows in parent table based on a value in child table
Consider the following tables, what would be an efficient query to return 1 row for each order that has at least 1 child row with a specific warehouse code? I am using SQL Server 2016. Table: Orders …
Joining two select statements together with outer join
My query on SQL Server: select s.learners_id, s.cv_student_id, s.first_name + ‘ ‘ + s.last_name student_name, p.program_name, dc.fulldate program_start_date, sd.discount_value, dt….
Case expression with Boolean from PostgreSQL to SQL Server
I am translating a query from PostgreSQL to SQL Server. I didn’t write the query in PostgreSQL and it’s quite complicated for my knowledge so i don’t understand every piece of it. From my understand: …
Unfiltered data in a group by statement – SQL Server
I have created a SQL statement using group by and some filters but I received an unexpected result: ID | Product | Brand | years | Sales —+———+——-+———-+———- 1 | car | 1 …
get records that doesnt exists in another table
I have a temp table over a 1000 rows but for example purposes as follows #Table and then i have another table as follows (this is not a temp table) Compliance Table how do i check if the records from the temp table doesnt exists in the Compliance table per its ID and Code so from the above data i
Sql update query using When condition
The example below apply null values into the field nom for the others id, how can forbid this action so that it does not modify the already existing values and that I do not wish to modify ? Answer One way is with else: But if you just want to update the rows that match, then use WHERE: No need