Upload and read dataset SAS - SQL Server - sql

I am uploading a dataset to MS SQL server, and I did it in two ways
first one:
proc sql;
create table lib.dataset as
select ID, date_reg from havingdata
;
Quit;
Here date format is YYMMDD10.
All went well, and date format also looks good on SQL server. However When i access the same from SAS, the date format changes to Date9.
2.I created the table directly on SQL server
create table dbo.dataset
(
ID char(11) NOT NULL,
date_reg date,
);
And then inserted the values from SAS
proc sql;
insert into lib.dataset
select ID, date_reg from havingdata
;
quit;
all went well, but again the same problem when I access the data from SAS, the date format changes from YYMMDD10. to Date9,
How can I get the same format as of in the SQL Server.
the libname I use is
libname lib odbc noprompt="dsn=myserver; database=dab" schema=dbo
bulkload=yes;

Related

What is equivalent to 'as table of' in SQL Server

I have a following query in Oracle that I need to convert to SQL Server
Oracle:
create or replace
TYPE "PARAMS" as table of varchar2(3000)
I am unsure how to convert 'as table of' object to SQL Server.
I'm pretty sure that's Oracle's way of creating user defined table types.
In T-SQL it would look like this:
CREATE TYPE Params AS TABLE
(
[value] Nvarchar(3000)
)

SQL Developer: Procedure To Insert In A table New Records from Another One

I'm triying to figure out how to insert records stored in the #TableA (STAGE_REMEDY) that does not exist in the #TableB (HIST_REMEDY). Comparing each other using the Date (FECHA_ENVIO field in my case), just to validate that I'd be inserting just NEW data and agrouping in the right way.
I'm using SQL Developer and I've tried to develop different procedures to reach my objective. My code below shows my tried that in fact does not work (Doesn't insert data in the table i don't know why). Also, I'm using SUBSTR , cause' the field has the date in the format (dd/mm/yyyy hh:mm:ss)
AS
BEGIN
INSERT INTO HIST_REMEDY (HORA_ENVIO, HORA_RESOLUCION,
TIEMPO_SLA_MINUTOS, GRUPO_ASIGNADO,INCIDENCIA,CUENTA,
RESUMEN,COMENTARIOS,ESTADO,
FECHA_ENVIO,FECHA_RESOLUCION,FECHA_ULTIMA_MODIFICACION,
USUARIO_ASIGNADO,REGION,CIUDAD,RESOLN1,RESOLN2,RESOLN3,
CN,NO_ACTIVIDAD,
OS,DEPARTAMENTO,ORGANIZACION,AREA,USUARIOR,NOMBRE,APELLIDO,GRUPO_ASIGNADO_MDA,AREA_ESCALA,
CATEGORIA_SLA,MAL_GENERADO,
USR_SIEBEL,NOMBRE_CLAVE,
AREA_PROVENIENTE,RECURRENTE,
ESCALADO,SEVERIDAD, SERVICIO)
SELECT HORA_ENVIO, HORA_RESOLUCION,
TIEMPO_SLA_MINUTOS, GRUPO_ASIGNADO,INCIDENCIA,CUENTA,
RESUMEN,COMENTARIOS,ESTADO,
FECHA_ENVIO,FECHA_RESOLUCION,FECHA_ULTIMA_MODIFICACION,
USUARIO_ASIGNADO,REGION,CIUDAD,RESOLN1,RESOLN2,RESOLN3,
CN,NO_ACTIVIDAD,
OS,DEPARTAMENTO,ORGANIZACION,AREA,USUARIOR,NOMBRE,APELLIDO,GRUPO_ASIGNADO_MDA,AREA_ESCALA,
CATEGORIA_SLA,MAL_GENERADO,
USR_SIEBEL,NOMBRE_CLAVE,
AREA_PROVENIENTE,RECURRENTE,
ESCALADO,SEVERIDAD, SERVICIO
FROM STAGE_REMEDY
WHERE NOT EXISTS (SELECT * FROM HIST_REMEDY WHERE SUBSTR (HIST_REMEDY.FECHA_ENVIO,0,10) = SUBSTR (STAGE_REMEDY.FECHA_ENVIO,0,10))
GROUP BY HORA_ENVIO, HORA_RESOLUCION,
TIEMPO_SLA_MINUTOS, GRUPO_ASIGNADO,INCIDENCIA,CUENTA,
RESUMEN,COMENTARIOS,ESTADO,
FECHA_ENVIO,FECHA_RESOLUCION,FECHA_ULTIMA_MODIFICACION,
USUARIO_ASIGNADO,REGION,CIUDAD,RESOLN1,RESOLN2,RESOLN3,
CN,NO_ACTIVIDAD,
OS,DEPARTAMENTO,ORGANIZACION,AREA,USUARIOR,NOMBRE,APELLIDO,GRUPO_ASIGNADO_MDA,AREA_ESCALA,
CATEGORIA_SLA,MAL_GENERADO,
USR_SIEBEL,NOMBRE_CLAVE,
AREA_PROVENIENTE,RECURRENTE,
ESCALADO,SEVERIDAD, SERVICIO;
COMMIT;
END;
My expectations is get a database where I can store all the new data gets on the #TableA (STAGE_REMEDY).
Regards!

Converting text field to date in SAS SQL

I am trying to convert a text field from a SAS table with the form '2014-12-31' into a another SAS table as a date field. The below does not work:
proc sql outobs=50;
create table Dbtr_Clnt_Generl_Inf as
select FACS_Schema_ID '',
'DBACCT*'n as ACCOUNT_NUM '',
DBLSTDTI as Date_Listed format=date09.
from sqlsrv10.Acct_Dbtr_Clnt_Generl_Inf;
quit;
I get the following error:
ERROR: Character expression requires a character format.
You use INPUT to convert types in SAS.
proc sql outobs=50;
create table Dbtr_Clnt_Generl_Inf as
select FACS_Schema_ID '',
'DBACCT*'n as ACCOUNT_NUM '',
input(DBLSTDTI,yymmdd10.) as Date_Listed format=date09.
from sqlsrv10.Acct_Dbtr_Clnt_Generl_Inf;
quit;
That is most likely the correct informat based on your question.

Change Date format during SQL

I am moving data to a new database and need to so some formatting during the move to try and save me time.
The current DB saves the date as YYYYMMDD and the new DB wants it in mm/dd/yyyy. Can I do this during the move or will I have to format after?
Thank you all!
You cold use the format function . So I am not sure how you are getting the data to sql 2014 but once the data is there you could use this command.
This is an example selecting from a table that has a date and altering its format .
use AdventureWorks2012
go
select modifieddate as 'original format', FORMAT ( modifieddate, 'd', 'en-US' ) AS 'New format mm/dd/yy'
from [Sales].[SalesOrderDetail]
Query Result
If your data is not format and its just a string you could use the format command to add the separators .
This code create a table with a date as an INT, the selects the data and formats it as a data time into another table .
CREATE TABLE Test_TimeString (Timeint int)
GO
INSERT INTO Test_TimeString VALUES(04242016)
GO
CREATE TABLE Test_Time (Timedate DATETIME)
GO
INSERT INTO Test_Time
SELECT FORMAT(Timeint,'##/##/####')
FROM Test_TimeString
SELECT * FROM Test_Time

sql developer data export date format is null

I'm using SQL developer connected to a db2 database.
I want to export a table to a list of insert statements. This works, but the problem is that dates are shown like:
to_timestamp('2016-02-08 11:07:54.01','null'),
There is no date format specified, so executing insert statements like this doesn't work.
I did set the date format in Preferences->Database->NLS
for 'Date format','Timestamp format' and 'Timestamp TZ format' to:
YYYY-MM-DD HH24:MI:SS.FF3
But somehow SQL developer keeps spitting out null values. Is there some other setting I need to check?