How to cast date column in SQL Server 2008 R2 to have drill down effect in the Excel format - tsql

I'm very new on this blog and probably I am not expressing my self correctly, but what I want is: I have a stored procedure where I am grabbing data and inside there I have a date column. I am using that stored procedure to create a report using SSRS and when I am exporting the report to Excel format and applying filter on date column I'd like to have a drill down effect on filter which shows first year and when I toggle down it should show me the month and then the days.
So how should I convert the date column that I can have a drill down effect?
CONVERT(VARCHAR(11), ORIGINAL_ORDER_DATE.THE_DATE, 103) AS ORIGINAL_ORDER_DATE
This is how i'm casting my date column inside the stored procedure.
This is how my date column look in Excel
This is how I'd like to have it

Related

How to correctly format dates in Power BI

I am connecting to a stored procedure in SQLServer, from the data source the column AnioMes arrives as follows:
Once loaded in PowerBI it has the same format as follows:
I would like to give the correct format separating the year and the month in new columns, someone can give me an orientation on how to do it.
If this is an import model, just convert the number to a date in PowerQuery. For beginners in Power Query Add Column From Examples is your friend.
If it's DirectQuery or Import, you should have a calendar table (aka a Date Dimension) in SQL Server that you can join this column to, and bring that into your model.

How to convert a specific text string to today's date in Power BI

I have a table with a column called that contains text. Most of the values are years. However, some have the value "present" to represent groups that are still currently active. I want to convert those values to today's year, and convert the column type to date (specifically year type). I want to avoid creating a new column if possible.
Please see below for the DAX language that worked.
= Table.ReplaceValue(#"Extracted Year2",null,DateTime.LocalNow() ,Replacer.ReplaceValue,{"Disbanded"})

SQL Server time datatype with format

Can I pass format for the time or date datatype in SQL Server 2008 R2?
Example: a column with time format like hh:mm ONLY
I searched and found that I can pass fractional second scale with like below but that is will get met a time format with seconds hh:mm:ss and I only want hh:mm
Note
I do not want to avoid this case in the select statement it wont help me in when using the column in Crystal Reports and I am not able to format it in Crystal Reports there is no date-time tab in format object option
_HOUR time(0);
I do not want to avoid this case in the select statement ...
I am not able to format it in crystal report
But you do need a select statement to produce a report, so one way is to use a "style number" (8) with the convert() function - but you only want the leading 5 characters, so use char(5) for the result. i.e.
select convert(char(5), [datetime_or_time_column] ,8) as "hh:mm"
from thetables
You do not indicate at all how you gather the data for the report, but if using a temp table or stored procedure (or even a view) you can use the convert syntax above when producing the result. Note is is possible to use T-SQL's format() like so format(getdate(),'HH:mm') but this is usually slower than using convert().
If you have permission to add calculated columns to your table AND this wanted hh:mm data is deterministic, you could also use the convert syntax shown above for a calculated column.

how to take off time in date time tabular model

I have a date dimension table and I have a Date column in that table it has datekey, fulldatekey, Date, DayofMonth, Dayofyear, month, ect. the Date column only has yyyy-mm-dd, but when I bring it into my tabular cube model it appends a 12:00:00 A.M time to the end of it. I was wanting to know how do I remove the time to only have the date. I am building a tabular cube in ssdt to bring into power bi
According to this Microsoft site,
In contrast to Microsoft Excel, which stores dates as a serial number,
PowerPivot date functions always return a datetime data type. However,
you can use formatting to display dates as serial numbers if you want.
From my "limited" experience, you can change the date formatting in one column, but when you reference it from another column, it will once again include the 12:00:00 AM time as part of the date when it displays in the new column. I assume this is because, as Microsoft says in that website,"PowerPivot date functions always return a datetime data type."
Edit Query -> Transform Tab -> Choose Data Type
That's my best guess.

date conversion in SQL parameter field in Crystal reports

I have a Crystal report (version XI r3) that uses a SQL command object to retrieve its data. In the command object I have a parameter for a date. My database uses "date" fields stored as numeric values in YYYYMMDD format, so I've specified the parameter as numeric and added a prompt to say "enter date in YYYYMMDD format".
My users don't much care for that; they want to be able to use the date-picker and/or to be able to enter the date in MM/DD/YYYY format.
My investigations so far have led me to believe that if I convert the parameter to a true date datatype, I won't be able to make use of it in the SQL command object because I can't convert it from a date to a number in the SQL statement, so I'd have to do my date-range control in the Crystal Select Wizard rather than in my SQL statement, which could slow my report down by an order of magnitude or two (since I'm hitting a table that is indexed by this date field, and that has a lot of records per day).
Am I wrong? Is there a way to let a user enter a date in MM/DD/YYYY format and still be able to use it as a numeric YYYYMMDD parameter in my SQL command object?
I'm afraid you would have to modify the original Command's to replace the numeric parameter with a date parameter, and do the conversion from date to number within the Command itself.
So, within the Command:
WHERE MyDate = {?MyNumberParam)
would become:
WHERE MyDate = (YEAR({?MyDateParam})*10000) + (MONTH({?MyDateParam})*100) + DAY({?MyDateParam})
The last part will convert 20th April 2012 to (2012*10000 + 4*100 + 20) = 20120420, which I believe is what you'd want.