Ok this one has been asked a million times but I can't find any answer to work for me. I have a column named 'Invoice Date' that is data type 'date'. I have an excel pivot chart that uses my query to update itself every 60 mins. Everytime this updates I lose my cell formatting and what's weirder, is that when I format the cells in excel to ie: Mar-14 then nothing happens, until I double click in each cell, then it displays correctly. This is vital because I need to group by months, and this is the only way I have been able to do this.
I have another date field in the query that is 'smalldatetime' and when formatting the cells in excel I just select the column, and format and all cells change without me double clicking. So I'm thinking maybe if I can convert the data in my SQL query to display the date similar to 'smalldatetime' that my pivot will work properly.
I have tried the checking of boxes in excel that CLAIM to preserve cell formatting... this obviously doesn't work for me.
Any help is greatly appreciated
You could try the following SQL in your SELECT statement:
CONVERT(VARCHAR(11),YourDateColumn,106)
the end result will be "02 Apr 2014".
You should be able to do so for smalldatetime type of column as well.
Related
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
Apologies if asked elsewhere, having checked couldn't find anything. I've got a SQL driven table in Excel. When my table refreshes, resulting in no data, it completely clears out a series of none-SQL driven columns on the far right of the table. Is there any way at all I can force Excel to store the formula on the cell, regardless of whether the row has cleared?
To ellaborate on my comment:
Below shows a simple query returning 10 dates from a database. The right column is a simple formula in excel adding 10 to the date:
If I update the query to return the top 0, you find the formula disappears because there are no values to assign the formula to:
But, I then update the query to bring back the original 10 dates again, and hey-presto, the formula re-appears!:
So I wouldn't think that you need to worry that it has gone. I would expect that they would come back once you return some values from your query.
FYI - More help on calculated columns can be found here from Microsoft support.
Thanks! I think I had 'preserve column sort/filter/layout' unticked - which was causing the formula to be lost when the data refreshed! Schoolboy error, thanks again
The data I'm pulling in from a SQL server is being displayed correctly as a date or number, but the data seems to be stored as text. For example, if I pulled in data with the number value 1, the cell would display "1" (no quotes) in it but Excel would not recognize it as a number - I can't perform any math to it and it won't be recognized as a number. I can fix that by selecting the cell and doing F2+Enter.
To clarify, the SQL data is not formatted in Excel as text. Changing formats does not solve my issue. The actual data in the cells isn't being recognized by Excel as numbers or dates, no matter what format I make the cells. I have to manually select and F2+Enter.
select distinct vl.Property As 'Property'
, vl.Property As 'Property number'
, vl.LeaseID as 'Lease ID'
, vl.priorleaseid as 'Prior lease ID'
from realpage_uds.dbo.property p
inner join realpage_uds.dbo.vwsa_lease vl
on p.propertyid = vl.propertyid
where p.name like '%Name%'
vl.LeaseID is a good example. It is data type "T-IDNumeric", system type "numeric" yet I can't select a leaseID and perform any arithmetic to it in Excel.
I'm pulling in the SQL data to Excel in the following way:
Go to "Data" tab, click "From Other Sources" under "Get External
Data"
Choose "From SQL server", enter server name to connect
Connect to a database and choose a random table in the database
Click finish, and choose to pull in the data as a table or pivot table. I've used both and they both have this issue.
Finally, update the SQL query under connection properties, and change the query to my desired query that I have typed up. Then I choose "SQL" and hit OK.
Has anyone else experienced this? Is there a way I can make the SQL data pull in as a number and date, and not have to manually select the cell and F2+Enter to get Excel to recognize the data?
Alternatively, if there is no way to change the way the SQL data pulls in, is there a macro I could implement to change all text data in a spreadsheet to number or date values?
Any help is greatly appreciated!
Wouldn't FORMAT(<<your field>>,'#') AS <<your alias>> solve your problem? Try using 'd' for date. I don't have much experience pulling data from SQL Server, but in Access that's how I'd try to work around this issue.
I had a similar problem with Dates. Excel only recognized them as strings. To solve the issue I created a view that converted the Date to an Int and then set up excel to recognize the Int column as dates.
To convert dates to Excel date integers you can use this function:
DATEDIFF(day,'1899-12-30',#yourDate)
I do not have experience with numeric types, but you may try and cast it to a decimal(18,4) which works for me in Excel.
The above works for me using Azure SQL.
So I'm pulling data from an external source which returns Date strings of the given format: "10/26/2013 9:46:46 AM"
When I sort the data it does not seem to be able to distinguish between AM and PM values so many noonish / 1 AM values are moved towards the bottom. Has anyone dealt with this before / have a solution to make it recognize the AM/PM aspect along with the day and time?
Thanks
It looks like it is sorting this as text. It may depend on how the data is getting pulled through.
If you select one of the cells and press F2 (to edit) then enter to go to the next cell, does this change your data?
In the code that is pulling the data through, you just need to amend it slightly.
Range("D5").value = string
It may change it slightly to maybe 24 hour time depending on your computer settings
I ended up just splitting the date and time using TimeValue() and DateValue() excel functions.I then wrote a macro to do a 3 key sort based on ticker, date, and then time.
I am getting data from SQL and pasting it to an excel sheet through VBA. The data comes in format
hh:mm:ss and I want excel to realize this is a time variable but that is not the case. Even if I select the pasted area and change format to any time format it doesn't seem to be working. It only works if I manually select a cell modify it slightly and click enter (or F2+enter for each cell) then it moves to a time format is there a way to fix this or is someone familiar with this issue?
How exactly are you getting this data into excel?
You would not happen to have Manual Calculation on would you? Excel will parse hh:mm:ss into a datetime, but it sounds like it is not recalculating after however you import this data.