How to take summary from a sql data Table using sql query - sql-server

I have a table with some data like subtotal,tax,Grand,Date
I want to take summary report from this data using Sql query.
when I use query its getting all the selected date's data (example: if start date 31-07-20, end date 01-08-20) then result showing each days details. My goal is to get summary of each days.
What I am getting:
What I am looking for:

SELECT SUM(Sub) as Sub, SUM(VAT) as VAT, SUM(Grand) as Grand, Date
FROM <WHATEVER>
GROUP BY Date
This is SQL 101...

Related

Get date in date format from SQL Server

I have a table in SQL Server with a date column set to default date, however, when I fetch the data from the server using VBA I get the date column in string format. Is there any way I get the date as in date format?
Can you you advise how you are bringing in the data? EG from inbuilt connectors or via a recordset via VBA objects?
A quick hack which I wouldn't advise without really testing would be this :
Select DateDiff(DD, '1899-12-30', date_column) AS [column] from TABLE_x
What is this doing?
In Excel dates start 01-01-1900. When you change a date to 'General' you find it's actually a number with a format. The above date difference will give you the excel number version of the Date.
EG to get today 29/11/2019 which will be 43798 when cell format is 'General'.
Select DateDiff(DD, '1899-12-30', '2019-11-29') AS [column]
More info here
Non MS site explaining the situation
MS Office Info touching on the subject
Please note this basing your question on a SQL formatted date.

In which date format should the Date column of my SQL Table be created to accept this specific date format?

I am using SQL Server 2014 and I need to create a Table with a date column. This column will receive an automatic input from a software on a daily basis. This software has the flexibility to connect with that SQL Table on my database and to feed it with its output.
My issue is that the date in the output column of the software is as follows: 2019-11-11 16:41:03
I have created my SQL Table and created a "DateReceived" column in the datetime format. However, when I try to create the mapping in the software with my SQL Table, it can't match its date column with the "DateReceived"column of my SQL Table.
Unfortunately, I can't edit the output from the software to format the date. My only solution is to format the "DateReceived" column in my SQL table appropriately. However, I am confused why the datetime format is not working.
Any help would be appreciated.

Increment Table Name Based on Current Date

I am trying to add a table into my power bi using the SQL Server data source. The thing is that a new table is added daily with the format of the year YYMMDD. Example: MYTABLE191121, tomorrow it will be MYTABLE191122.
How can i write a query in Power BI that always looks at the latest table based on today's date? I want to be able to refresh the content and have latest table's data.
Thank you
If your database name is TEST_DB on localhost your query can be like this:
let
Source = Sql.Databases("localhost"),
TEST_DB = Source{[Name="TEST_DB"]}[Data],
// chain a few functions to create today's date in YYMMDD
TODAYS_DATE = Text.Range(Text.Remove(Date.ToText(DateTime.Date(DateTime.LocalNow())),"-"),2),
// simply use & to concat MYTABLE and today's date
todays_table = TEST_DB{[Schema="dbo",Item="MYTABLE" & TODAYS_DATE]}[Data]
in
todays_table
This will create a query like this: SELECT * FROM [dbo].[MYTABLE191122] into the table todays_table.

Would like to use this SQL Server date exactly in Oracle query

2017-11-17 06:35:41.0000000 - this is a value of a column FileProcessDate in a SQL Server table. I am trying to build an incremental logic and I would like to use this date (directly) in Oracle to build that logic.
I am using the following query in Oracle
SELECT *
FROM EVENT
WHERE TIMESTAMP > TO_DATE('2017-11-17 06:35:41.0000000', 'MM/DD/YYYY HH:MI:SS')
But I am getting an error
not a valid month
You need to use correct timeformat:
SELECT *
FROM EVENT
WHERE TIMESTAMP>TO_TIMESTAMP('2017-11-17 06:35:41.0000000','YYYY-MM-DD HH24:MI:SS.FF')
DBFiddle Demo

Query works in Query Designer but not in MS SQL Server Report Builder

While using the Microsoft SQL Server Report Builder, I am able to execute a query in the Query Designer and retreive the result. The query has a where clause on dates.
select * from table where DB_timestamp > to_date(:StartDate, 'mm/dd/yyyy') and DB_timestamp < to_date(:EndDate, 'mm/dd/yyyy')
On execution, I get a pop up where I enter the two variables (StartDate & EndDate) in the given formats. Now when I try to run the same for generating a report, I have to select the two variables using a calender picker. Altough the dates show up in the desired format, I always get the below error:
An error occured during local report processing.
Query execution failed for dataset 'XYZ'.
ORA-01843: not a valid month
What can cause the query to run successfully in one place but throw an error when the variables are selected by the calender picker?
There mught be some kind of culture clash going on. If SSRS is sending dd/mm/yyyy and your db is expecting mm/dd/yyyy things will not work as expected or even crash on certain dates.
I would remove the to_date function from the where clause, e.g.
where DB_timestamp > :StartDate and ...

Resources