I have a simple stored procedure to return a datetime. e.g:
create procedure sp_get_date (#db_date datetime output)as begin select #db_date ='2017-04-26 13:20:32.313' end
And using SQLNCLI11 native client to work with the datatbase inside the PowerBuilder application.
DECLARE get_date_proc PROCEDURE for dbo.sp_get_date #db_date = :dt_today output using sqlca;
EXECUTE get_date_proc;
FETCH get_date_proc INTO :dt_today;
t_now = time(dt_today)
The expected result for t_now is "13:20:32.313000"
When use SQL sever 2014, the t_now value is correct with 13:20:32.313000
But with SQL server 2016, the value is 13:20:3133333
Is that the problem with native client library to work with SQL server 2016? Is the stored procudure return a datatime2 value?
Thanks a lot.
It looks like you are running into this sql server bug (https://connect.microsoft.com/SQLServer/Feedback/Details/2805477). So it seems the best approach may be to convert the datatype of your parameter to datetime2. Alternatively, it might help to implement the procedure as a RPC in your PB app; I can't really say if that does anything since I'm still using ss 2012.
Related
Oracle version 12.1.0.2
max_string_size=extended
I am using sql server ODBC to connect to sql server database via Oracle gateway to sql server, the connection is working fine and i am able to access sql server tables.
However, as per Oracle documentation starting 12c and with extended limit on varchar2 data type the conversion of sqlserver varchar(max) to oracle Long will only happen if the length of sql server data is more than 32k.
My sql server table has few columns defined as varchar(max) in and all of those i see getting converted to LONG when i try to describe the table over dblink.
I need to load the data from sql server to oracle and the above problem is making it very difficult as more than one long columns can not be copied over dblink.
Any help will be deeply appreciated.
I created a view on the SQL server side that uses substr(column,1,4000) to fit within the old Oracle max 4000 character length. This worked quite well with Oracle 11.
I am in the process of migrating to a new Oracle 18 instance that uses character set AL32UTF8 instead of WE8MSWIN1252. The exact same SQL is now getting:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Microsoft][ODBC Driver Manager] Program type out of range {HY003}
ORA-02063: preceding 2 lines from CEAV195
Fortunately I don't have a tight deadline for working this out.
Comment: I am now getting
[Error] Execution (8: 17): ORA-00997: illegal use of LONG datatype
despite using the following in the view on the SQL Server side:
cast(substring(cr.response,1,2000) as varchar(2000)) response
As I said earlier, this worked perfectly fine with Oracle 11 and the WE8MSWIN1252 character set.
I hit the same issue and found this solution elsewhere
set serverout on
DECLARE
l_cursor BINARY_INTEGER;
l_id VARCHAR2(60);
l_temp VARCHAR2(250);
l_notes VARCHAR2(32767);
BEGIN
l_cursor := DBMS_HS_PASSTHROUGH.open_cursor#remotedb;
DBMS_HS_PASSTHROUGH.parse#remotedb(
l_cursor,
'select "RecId","Notes" from "MySqlServerTable"'
);
LOOP
DBMS_HS_PASSTHROUGH.get_value#remotedb(l_cursor, 1, l_id);
DBMS_HS_PASSTHROUGH.get_value#remotedb(l_cursor, 2, l_notes);
DBMS_OUTPUT.put_line(l_id || ' ' || l_notes);
END LOOP;
exception
when others then
DBMS_HS_PASSTHROUGH.close_cursor#remotedb(l_cursor);
raise;
END;
/
I have been trying to call a SQL Server stored procedure that has no parameters and no return values. All it does is recalculate data in a SQL Server database.
I thought I could use something simple like
lsqlcmd = " execute storedprocname"
but the procedure is not being called and I am not receiving an errors.
Any suggestions?
Can you try calling it in SQLEXEC()? This how I've seen it done:
TEXT TO lcSQLCommand
<database>.<schema>.<sproc>
ENDTEXT
gcConnectionString = [Driver={SQL Server Native Client 10.0};Server=] + "<servername>" + [;Database=] + "<database>" + [;Trusted_Connection=yes]
STORE SQLSTRINGCONNECT(gcConnectionString) TO gnConnHandle
SQLEXEC(gnConnHandle, lcSQLCommand)
You'll need to update the connection string to however your database is configured, this was for windows authentication.
I'd like to insert a date field into a SQL server table form Proc SQL in SAS. Here is my code for Proc SQL:
proc sql;
insert into CFS_SQL.Data_DSB_Raw(sasdatefmt=(TheDate='mmddyy10.'))
select TheDateIncoming
from Work.Upload;
quit;
According to the SAS help documentation (http://support.sas.com/kb/6/450.html), this should work as long as TheDateIncoming also has format mmddyy10.. I've verified that the format on TheDateIncoming is correct, so I think this should work.
Unfortunately, however, I'm getting a "Value 1 on the SELECT clause does not match the data type of the corresponding column" error.
Any thoughts?
Annnnnd... solved. It actually had nothing to do with the code. It was a driver problem. Switching to the SQL Server Native Client 11.0 ODBC driver fixed the issue.
I try to inset date into SQL server from textfield. I already tried to convert it but I always keep receiving same error:
Stored procedure 'XYZ' expects parameter ... which was not supplied.
Before I pass value of date to SQL Server I convert it into date:
upis.parameters.AddWithValue("#datum_start", DateValue(Datum_start.text))
I captured SQL Event with Profiler and I see that form passes value:
exec sp_executesql N'_osoba_zivotopis_test',N'#guid_kandidata nvarchar(36),#datum_start nvarchar(10),#datum_kraj nvarchar(10),#vodece int,#trenutno int',#guid_kandidata=N'24C40512-7292-403D-8C08-EEEA2C81EC7D',#datum_start=N'15.02.2012',#datum_kraj=N'01.10.2012',#vodece=0,#trenutno=0
Any ideas on this?
Thank you Sankaras, but problem was on the other side.
After writting 305 lines of code I missed to add code in stored procedure definition in my VB.NET code behind file
upis.CommandType = CommandType.StoredProcedure
When I defined CommandType everything works fine.
.NET knows to pass date value to SQL date data. Even I collect it in my form in local code environment .NET knows how to pass it and SQL knows how to handle it without convert(date,<varchar/nvarchar>,110)
I saw it after 10 minutes but I had to wait for 8 hours for post the answer...
Thank you guys.
Here I have a question about data converting regarding SQL Server and SYBASE.
Take 71632.0638353154 as an example, how to convert it to 71,632.06 in SQL Server and SYBASE?
I know that there is a convert() function in SQL Server and SYBASE, but every time when I tried to use it to convert that number, the database UI will throw me an exception.
I use sybase UI to excute below SQL instance:
select convert(varchar(30),convert(varchar(8),convert(money,71632.0638353154),1))
but this causes this error:
Insufficient result space for explicit conversion of MONEY value '71,632.06' to a VARCHAR field.
Would anyone tell me how to do it? thx.
I'm unable to test in Sybase but
SELECT CONVERT(VARCHAR(30), CAST(71632.0638353154 AS MONEY),1)
works for me in SQL Server.
The more generic solution is:
select cast(71632.0638353154 as decimal(10, 2))
The cast function is standard SQL and available in most databases. DECIMAL is a built-in data type.