Oracle/SQL Server Database Link Date Format Issue - sql-server

I have an Oracle hs database link set up between SQL Server 2012 and Oracle 11g.
When Selecting date columns in Oracle from the SQL Server database the date comes through fine but as soon as it has to pass through any function then the date gets cropped from 10 to 5 characters.
For example:
Select Input_Date from schema.table#Database
would return 2000-08-18
Select Len(Input_Date) from schema.table#Database
would return 5
(Select Input_Date from schema.table#Database1
Union
Select Input_Date from schema.table#Database2)
would return 2000-
I am at a loss at what to do, at first the select statement also returned 2000- but then I changed the NLS_DATE_FORMAT parameter which allows a view of the full date in a select statement but has not fixed any of the other issues.
When I select dump(input_date,1016) from schema.table#Database I get
Typ=1, Len=10, CharacterSet=AL16UTF16.
I would really appreciate some help as there seems to be very little information about this online.
Many thanks.

Related

Conversion Failed Varchar to Date with TOP and WHERE

I've got a MSSQL 2012 server that holds olders databases (day by day) of my ERP. Simple JOB restores a newest databases from my backup server and removes the oldest one's. It was working fine for few months, but a week ago it started to fail. One of the queries returns: 'Conversion failed when converting date and/or time from character string.'
All database have the same schema for a name 'DATABASE_date' ex.: 'DATABASE_20150224'.
This is the query:
SELECT TOP 1 name
from sys.databases
where name like 'DataBaseName_%'
order by CAST(right(name,8) as DATE)
IF i remove 'TOP 1' it works fine.
SELECT name
from sys.databases
where name like 'DataBaseName_%'
order by CAST(right(name,8) as DATE)
It seems like MSSQL check's all databases on this server (2 new databases of a different app). But why? There's a 'WHERE' cluase and simple select works just fine.
SQL is a declarative language. A database is free to first order the rows and then filter them, or the other way around.
You are relaying on a where clause to filter out rows that would cause an exception in your string manipulation expression. But SQL Server can run the where after the order by.
One approach is bullet-proofing the order by:
order by
case
when name not like 'DataBaseName_%' then name
else CAST(right(name,8) as DATE)
end
Note that even this isn't 100% guaranteed to work. SQL Server could legally evaluate both sides of the case and throw away the second one.

Operation must use an updatable query Microsoft Access 2010 running on SQL Server 2012

I have an Access 2010 FE , with linked tables on SQL Server 2012. I have several queries which are passed through used for the generation of reports.
After migration and recreation of the queries. When I run the reports it throws up the above error.
I did check the permissions and also tried unchecking "Use simple file sharing (recommended).
I have full access for the account which I'm using.
Here are some pass through queries example that I have in my DB,
1.UPDATE TABLE SET TABLE.COLUM=TABLE.COLUMN WHERE CONDITION
2.INSERT INTO TABLE (COL1......) SELECT * FROM TABLE
3.DELETE FROM TABLE
INSERT INTO TABLE (COL1......)
SELECT * FROM TABLE LEFT JOIN ON CONDITION LEFT JOIN CONTIDION WHERE CONDITION
Could you please let me know what settings or changes I need make to correct the above issue.
Thanks in advance , I have moderate knowledge on SQL and MS Access any help is greatly appreciated.
#GordThompson I took your option 1 , started decoding all the queries that are being called in VBA code , I had all my tables linked from SQL Server with return records set to false.
I was able to correct the error , it was a violation of data type where a column with int and float where updating a column with nvarchar , this happened due to not defining them explicitly in the SQL statement.
Thanks for the tips.

How to get a list of tables that has updated values

.Hi everyone, I need a little help on coming up with a query that lists all tables whose data was updated from a certain date to present.
I'm using SQL Server 2012.
TIA!
Addt'l info:
This is the query that I have so far:
Select distinct OBJECT_NAME(object_id) As TableName
From sys.dm_db_index_usage_stats
Where user_updates > 0
And last_user_update > cast('07/17/2012' as datetime)
order by TableName
I wanted to get all the tables that had its data updated or new data inserted from 07/17/2012 to present.
I haven't done a ton of work with SQL Server since leaving my last DBA job several years ago, instead I focus more on MySQL but I had to do something similar back then and found this article helpful. Hopefully it sheds some light...
http://blog.sqlauthority.com/2009/05/09/sql-server-find-last-date-time-updated-for-any-table/

Query in SQL Server Management Studio fails to pass date to linked InterSystems server

I have a SQL Server and Cache server and need to combine some data. Most all functions are working, except when I attempt to pass a date with a variable or a parameter.
Below is a test I ran (one of many).
declare #myDate datetime
set #myDate = convert(datetime,'2012-02-01',120)
select * from ccms..dbo.dcdnstat where timestamp > '2012-02-01' -- WORKS
exec( 'select * from dbo.dcdnstat where cdn = ?', 21004) at ccms -- WORKS
exec( 'select * from dbo.dcdnstat where timestamp > ?',#myDate) at ccms -- ERROR 7213
select * from ccms..dbo.dcdnstat where timestamp > #myDate -- ERROR 7322
Msg 7213, Level 16, State 1, Line 9 The attempt by the provider to
pass remote stored procedure parameters to remote server 'ccms'
failed. Verify that the number of parameters, the order, and the
values passed are correct. Msg 7322, Level 16, State 2, Line 11 A
failure occurred while giving parameter information to OLE DB provider
"MSDASQL" for linked server "ccms".
I have tried different date formats, and as shown above I can query on other fields with variables and I can query on date if I use a specific value.
Instead of a "DATETIME" type for your stored procedure parameter, just use "DATE"
(as long as you don't need the time requirements)
I had a problem similar to this today. It had to do with the fact that the calling server and the linked server were not the same version. One was SQL Server 2005 and the other was SQL Server 2008. The problem was due to the fact that the column being queried against at the remote end (2008) was a datetime2 and the calling server (2005) does not support datetime2.
I know this is a little late but I stumbled upon it looking for something similar with the Cache system. Looks like we are working on the same backend system. Mine is the Avaya CCMS system. Here is what I do to pass dates as variables:
DECLARE #myDate DATETIME
SET #myDate = CAST('2012-07-01' AS DATETIME)
SELECT SUM(CallsOffered), SUM(CallsAnswered), SUM(SkillsetAbandonedAftThreshold)
FROM AvayaCCMS..dbo.mSkillsetStat
WHERE Timestamp = #myDate
I was doing something very similar using a Sybase database as the linked server. Just as MobileMon said, I was able to change the datetime to date and it works fine now.
declare #myDate date
set #myDate = convert(datetime,'2012-02-01',120)

Execute query once in SQL Server despite being called mutiple times

I have a situation where a query might be called multiple times from multiple users, but I only want it to run once (per week) against the database. The environment is SQL Server Express so scheduling via SQL Server Agent is not an option. It needs to be 2005 compatible. I'd like to make it as lightweight as possible too, so I'm asking for suggestions. Ideally a database wide declared variable - but I don't think that SQL Server supports such a beast? Thanks
Try something like this:
IF NOT EXISTS ( -- Check if you have the current week content
SELECT *
FROM WeeklyTable
WHERE
DATEPART(YEAR, DateCr) = DATEPART(YEAR, GETDATE())
AND
DATEPART(WEEK, DateCr) = DATEPART(WEEK, GETDATE())
)
BEGIN
-- delete old content
DELETE WeeklyTable
-- insert new content
INSERT INTO WeeklyTable (MyID, MyField1, ... , MyFieldN, DateCr)
SELECT
MyID, MyField1, MyField2, GETDATE()
FROM MainTable
END
You can create indexes you need for the WeeklyTable.
One option would be SQL Scheduler as a add-on to SQL Server Express.
The other option would be to create a small command-line utility that does the querying and schedule that using the Windows Scheduler on the machine where SQL Server Express is installed.
With either of the two setups, you could select the values / numbers you need into a result table once a week, and any requests during the week would be satisfied from that one result table. SQL Server doesn't have "server-wide" variables - but you can always define a table for that purpose...

Resources