I have requirements to get the current month of the year and the last year’s month. Something like this: Right now what I did is hard code it like this: , ISNULL(SUM(CASE WHEN month(trans.DocDate) = …
Tag: sql-server
Fetch rows for the last 6 hours in SQL Server
I run a Microsoft SQL Server SELECT query and have an issue trying to define a specific time range for that query every 6 hours (I am a newer user of SQL Server). I have an external script calling …
Compare two tables and combine records with status in SQL Server procedure
I have table A and table B . I have to compare this 2 tables records and return data using SQL Server procedure in below format. table A table B Expected output is like below. It has an extra field ‘status’ to mention record is added or removed. I tried code like below But in output, newly added r…
how to use GROUP BY based on 2 specific columns
I have a table in SQL Server which looks like this : each ticket id can have multiple order issue. On each row I need to calculate ticket full revenue as below : SUM(revenue) of all items within the same ticket id So in my case, ticket id has 3 items (10,20,30) so the ticket full revenue = 30+5+15 =
Need to copy all fields value of specific item on table to another item in SQL Server
SQL Server database snapshot: I need to copy this selected article data to another article. Need a query in SQL to solve this issue. Answer If I understand, you wan the IEDetails table to have the values for art_id = 7545 copied with a different art_id value while still retaining the original values? With the…
Any suggestion for optimizing BCP export from SQL Server using Python Subprocess
I’m studying BCP for export large amount of data (one time for initial and plan to do it in day-to-day job). Source data are in SQL Server tables, which consist of some small tables to larger ones (…
Increase the value of a column
I want create a CTE or something that subtract a know value from a sum() of value. How can I solve this, I tried to use LAG() on my CTE but it faulted when my value is negative. This is what I tried to do: This is the result of the query And this is what I expect from the
How to check if an int contains another one as part of it?
The question is fairly clear. I wanna check if for example a number x is contained in another number y. And I wanna do it in SQL (also in LINQ if possible). Additionally those integer values(y values) are Ids from a table. So when LINQ is concerned, I am not looking for some general solution like: Examples: A…
Remove Duplicate Time Zones From SELECT query
I need help removing duplicate time zone records from my select query without deleting them. The current result is as follows: The table returns duplicate GMT start times for the same employee, the database appears to be duplicating the results based on different time zones. I just want to remove the duplicat…
Group by using linked tables
I have linked tables. Calls and Call Lines, both tables have a seperate ‘Call Type’ field, I am trying to get the number of calls and the number of call lines which were added on a certain date and then see the split for the types. The below query returns the number for each Call Line which was ad…