Automatic date in pivot in stored procedure - sql

As I am less aware of Stored Procedure can anyone help me out with automatic date in pivot as I want the user to select start date and end date and I want to display all the selected dates as horizontally. As till now I am using dynamic dates by writing dates in pivot but I want it to display all the dates from the start date to the end date automatically.
Can anyone help me?
As it should display date as 01,02,03,04,05 up to the end date

In SQL Server you cannot. The column names are part of the query. Dynamic is the way to go, but be careful - dynamic results from SPs are difficult to consume. You might want to rethink and go traditional row-based doing the pivot in your front end.

Related

MS-Access conditional format date in tabular forms row by row

I have created a database to store genealogical records. I have created a tabular form to display records which include a date text box, however I am struggling to display the date text boxes with the formatting different on each row. The different formats I require are "dd/mm/yyyy" where a full date is known, "yyyy" where the year only is known, and the text box to be left blank if the date is unknown. The table the form is aligned to has a field to indicate whether the date is a full date, year only, or no date - field values "fd", "yo" and "nd" so easy to test the format required for each row.
I cannot see how this is possible using the Conditional Format option.
I am happy to use VBA but have struggled with this. I am new to Access and new to VBA but have a technical background (coding in C++ and Java) and VBA currently looks alien to me - but willing to get into it.
Any pointers please will be much appreciated.
Always store dates as DateTime as it can be stored as Null for unknown.
Then, have a Boolean field, YearOnly, to mark values where only the year is known; store the year with any date of the year, like 2020-01-01.
Now, use a query like this:
SELECT
ID,
[Date],
YearOnly,
Format([Date],"yyyy" & IIf(Not [YearOnly],"-mm-dd")) AS DisplayDate
FROM
YourTable;
[Solved] Thank you Kostas K and Gustav, I have implemented the query you suggest, which took me a while to figure out, but I have it now working in my tabular form. My problem was I was trying to achieve this using VBA on loading the form. VBA wise I am a complete novice.
Thanks Bob H

Creating a date calculated field in tableau

I have a starting date, and an end date in tableau, is there a way to create a calculated field with all date (months) ranging from my start date to my end date?
If you're just looking for a visual solution, if you place a Month(date) discrete dimension in your columns bar, right click on it and click on 'Show missing values'. That would force nulls to show, e.g.
Although what you have specifically asked for sounds like you're looking to do 'data densification' or 'data padding'. You'd have to think about how that generated data would relate to the existing data.
It might also be easier to create a static file with the month/year in columns and (left) join that to the data set you are using. Then you have something you can reuse. I'd recommend that approach.

SQL. Query for vba

I have a table that has more than one date fields (say six or seven) and I just want to retrieve only the dates that match today's date. Please help. Really appreciate it thanks
This is a very specific problem, so the best way to get the result you want is to code some part as an script on access.
For getting those rows where at least one date is the same as today's date, you should use something like this.
SELECT * FROM Table t
WHERE Date() IN (t.field1, t.field2, ...)
You should add all the fields you want to check inside IN clause.
On the Access for you should be able to process the data.

Need Date Calculation MS Access

I need a flexible table that displays dates. By flexible, I mean, if I put in June 15, 1976, it displays as such. But if I put 20, Access calculates that 20 in the same field as today's date - 20 years.
I set the formatting of the date/time field in table: tbl_ageLimit to #, so it displays a serial date rather than a user readable date. This table has one field: ageLimit.
I am trying to develop a query to recognize if the date is not relevant in its current state and then convert it to something relevant and put it in another table that will constantly update.
Right now, I'm just trying to get formula to work on recognizing and converting the date. This is the formula that works splendidly in excel, but doesn't seem to be working in MS Access:
IIF([ageLimit]<=100,Date()-365*[ageLimit],[ageLimit])
It recognizes if the field has a number in it that is less than 100. But it's not doing the math and displaying a new record in the new table. Below is the sql:
SELECT tbl_ageLimit.ageLimit INTO tbl_allAges
FROM tbl_ageLimit
WHERE (((tbl_ageLimit.ageLimit)=IIf([ageLimit]<=100,Date()-365*[ageLimit],[ageLimit])));
Can someone kindly point out to me what I'm doing wrong? Thank you.
As requested, here are snapshots of the problem:
The table that is created is not showing the fifth record. Stumped.
Consider removing the WHERE clause as you do not need to filter records. Since you intend to evaluate the IIF() expression, place in the SELECT clause:
SELECT IIf([ageLimit]<=100, Date()-365*[ageLimit], [ageLimit]) As [age_Limit]
INTO tbl_allAges
FROM tbl_ageLimit

SQL - how to add every day a new column in 1 query without INSERT, UPDATE, etc

I need to add every day to some query result a column A for sysdate, and next day as well, and next day as well, etc.
So you will have the same select which will always add for new day a new column for actual date.
Is this somehow possible in sql without using INSERT, UPDATE and other rewriting statements?
Thank you very much for your answers :)
Im using a Oracle SQL Developer
SQL queries give you a fixed number of columns and a variable number of rows. If every day means more data to you then you would have a query to result in more rows usually. It's up to a GUI to display retrieved data in the most convenient way (one column per day in your example).
So, yes and no. Yes, you can (very easily) write a query to give you more data each day. No, you cannot write a query that results in a new column every day. But as mentioned, this is not what SQL is made for anyhow. SQL is the data retrieving language. You use a programming language or a report tool to display the data to your users.