I am exporting data from an existing sql server 2012 table by using the ssms option database right click -> Tasks -> generate scripts. This works fine except for date columns.
Example output:
INSERT INTO Employees VALUES (1, 'Frank', ,CAST(0x16190B00 AS Date));
I Don' find a way to export date columns to a format like 2.10.2012. I can think about adding a string column and cast the date column values as a string, but this is just a work around.
Can someone help me out here?
Like Mikael said, this is a bug which will be fixed in the next major release of SQL Server
Related
I am trying to extract individual dates from a varchar column in a SQL Server 2016 tablet that are stored comma separated and am not sure how to proceed. The data is setup like this:
article Consolidation_Order_Cut_Off_Final_Allocation
------------------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
011040 01/13/2021,03/10/2021
019099 01/13/2021,01/27/2021,02/24/2021,03/24/2021,04/28/2021,05/26/2021,06/23/2021,07/28/2021
019310 01/27/2021,02/03/2021,03/10/2021,04/14/2021,05/12/2021,06/09/2021,07/14/2021,08/11/2021
059611 01/13/2021
Ideally - I would have each date split out into a new row. I have seen a few similar questions that use very complex functions but those seem to be for SQL Server 2008. I have also found the new function STRING_SPLIT but that would seem to be table valued and thus have to come in the FROM. One thought I had was to declare a variable to hold this column and then use something like select * FROM string_split(#dates,','); however since there is more than one value in that list that returns an error. I am very new to the 2016 version of SQL Server and curious if anyone has ran into a way to solve this.
String_Split() is a table valued function, so you can call it with a CROSS APPLY
Example or dbFiddle
Select A.article
,B.Value
From YourTable A
Cross Apply string_split(Consolidation_Order_Cut_Off_Final_Allocation,',') B
I need some help, I'm pretty new in SSIS and have some basics in SQL Server.
I have a SQL query within a package in SSIS, I tried various solutions (STUFF(), STRING_AGG(), SUBSTRING()...), but every time I got some errors.
I have a file source with data that looks like this:
Name,Active,AccountNr,Comment
Alex,30,895478548,Food,
Alex,50,895478548,Sport,
Alex,30,5544440000,Travel,
Fabien,15,4555555,Car,
Fabien,2500,63553336,Family,
Fabien,2500,4555555,Health,
Alex,30,895478548,Travel
I want to add the actives and concatenate string values of Comment column (which have the same Account number) in one row from multiple rows
For example, rows 4-6 have the same Account number, then we should get
:Fabien,2515,Family/health
as output.
Doesn't SSIS supports string_agg()? If so, you can do:
select name, account_number, string_agg(comment, '/') all_comments
from mytable
group by name, account_number
I have severe troubles to set up an MS access application that uses linked tables to an SQL Server 2012 Database.
The problem is that SQL Queries have problems to interpret German dates: e.g. "31.12.2019" doesn't work, "01.01.2019" works. So I suspect that it is a problem with localization. E.g.
select * from table where date >= [Forms]![someForm]![fromDate]
[Forms]![someForm]![fromDate] is a string in a form, edited by a date picker.
I was able to solve the problem by using the ODBC Microsoft SQL Server Setup Wizzard, and selecting "Ländereinstellungen verwenden" (engl. use country specific settings).
(Sorry the following screenshot is in German).
I would like to specify this in a classic ODBC connection string: e.g
DRIVER=ODBC Driver 13 for SQL Server;SERVER=.\SqlExpress2012;Trusted_Connection=Yes;APP=Microsoft Office;DATABASE=suplattform;?country-specific=yes?
However I did not find such an parameter in any documentation. Is this possible?
Best regards
Michael
Also, specify the data type of the parameter - and date is a reserved word in Access SQL:
parameters [Forms]![someForm]![fromDate] DateTime;
select * from table where [date] >= [Forms]![someForm]![fromDate]
I am a SQL student who has been tasked with loading data into SQL Server for a company that I intern with.
I have tried loading multiple flat files with dates formatted as 1/23/04 into SSMS and when going through the wizard the dates preview correctly. Once they're loaded into the actual database and a select query is performed, all dates return as 2023-01-04 format.
I'm not sure where to even begin to fix this. I've loaded columns as nvarchar(50) as opposed to date, datetime, and datetime2 to see if it would make a difference, and each case returns the same format. Is this a setting in the flat file, SSMS, or the computer itself?
In SSIS bring in the column (with the dates) as a string and add a derived column transform that will transform the column (using the substring function) to the correct date. SQL Server loves seeing dates as YYYY-MM-DD so that is why without explicitly telling it how to read the string it defaults to thinking that the inputted date is of that format.
If you are using SQL Server (SSMS) you should input it as a string (char(8)) and then use cast or convert functions to change the string into a date. You can then issue a 'Alter table drop column' to drop the string version column of the date.
I am importing data from postgres into sql server. Fields where data type is 'timestamp without (or with) time zone' i used datetimeoffset in sql table but couldn't create package with the same. So i changed the datatype as datetime.
Now, when I import data,all the dates and time are coming perfectly alright but where there is no data ( blank) then its displayed as some weird date instead of NULL in my SQL table.
Those weird dates are -
1899-12-30 00:00:00.000
1753-01-01 00:00:00.000
What am i missing and how to resolve this?
Maybe that's a simple thing but I am quite new to SQL so apologies if its really easy but any help is appreciated.
Thanks,
AP
Suppose your meaningful data is from 2000 onwards, then run a update statement like:
update table
set column = NULL
where column < cast('01-01-2000' as datetime)