I need to create a Sales Report that shows all years sales per month, and cumulative sales. The database table is simple: I want the results to look similar to ExcelSheet below (I am showing only 2017/2018 amounts, but actual query needs to return results for all available years according to TransactionDate) Answer Try it:
Tag: tsql
PROCEDURE Return always 0 for string statement
I have a procedure that can be changed dynamically by user for multi column and I write it in SQL when I run it. Everything is OK in SQL and Server Explorer in Visual Studio but when I want use it in …
Joining two different tables with a common third table on a common column
Here are the tables Table: Status ID, StatusDesc 1, New 2, Active 3, Cancelled 4, Complete Table: Order (foreign key relationship with Status table above) ID, OrderNumber, StatusID 1, 1001 , …
How to rename database file programmatically?
I have two databases: database_A. Name of file is database_A.mdf. database_B. Name of file is database_B.mdf. Then I what I do: Drop database_A. Rename database_B to database_A: sp_renamedb ‘database_B’,’database_A. However, name of file is still database_B.mdf. Is it possible just by code rename database_B.mdf to database_A.mdf without setting path to location of databases? I cannot use Management Studio to deattach
columnA like %columnB
I’m trying to do select * where column1 = % column2 %. this is my query The error: The data types varchar and text are incompatible in the add operator. Answer You can cast the text to a varchar(max): Or, if b.Client is a text too: Notes (most of which already were commented): text is deprecated; you want to use
Loop and insert more than one comma separated List in SQL
I wish to loop through two comma-separated values and perform an insert As an example lets consider two variables Using this loop I am able to extract @Answers and can perform insert. But I wish to extract @Qid and insert inside the loop. edit for more clarity it is a feedback module. my result table have Qid and Answer field.
SQL: INSERT multiple different hardcoded values in one column
I could not find a solution for this yet. I want to insert multiple rows with 2 or more different hardcoded values, but also with data that I get from another table. Example: I want to add 2 items into a table for a user that has the ID = ‘0’ in another table without running 2 queries. This is
T-SQL, looking to extract drug dose from column
I have a column of drug names with dose and I’m trying to extract the just the dose from the field. The difficulty comes in when I have combination drugs that have multiple doses. I can either extract the first numbers in the string, or all of them in one string with no way to separate them. Desired output I
Add new key with value = NULL to existing JSON object
I have the following simple JSON object: I’d like to add a new key under application called “approve_date” and would like the value to be NULL. Is there a way to do this with JSON_MODIFY. I tried using ‘append’ in the path but this added an array, not a key (example below). What is the better way to (A) add
group by issue in sql
i’m trying to get in a new column the sessions who are between 08:00 and 18:00. You can see my last CASE in the CTE. For each date there should be a new column “TotalRestrictedSessions” which indicate how many session were on that particular date. If there are none, in this case i have to write 0. I suspect that