I am trying to update a table in a server(ServerA) using a linked share connection from ServerB and i Got the below Error
The OLE DB provider "SQLNCLI10" for linked server "ServerA" could not
UPDATE table "[ServerA].[MyDb].[dbo].[tbl_name]" because of column
"CreateDt". Conversion failed because the data value overflowed the
data type used by the provider.
This is the query I Used :
update [ServerA].[MyDb].[dbo].[tbl_name]
set transfer_fl = 1,
CreateDt = getdate()
where transfer_fl<>'1'
the column CreateDt is of data type smalldatetime and it already has a value in it.
Can somebody give explain me why this happens.
This is a bug in SQL 2008/R2.
https://connect.microsoft.com/SQLServer/feedback/details/430745/sql-server-2008-unexpected-behavior-when-inserting-datetime-value-in-smalldatetime-column-on-a-linked-server
Unluckily it is marked as won't fix and you would have to do an explicit conversion.
GETDATE (Transact-SQL)
Sintaxis
GETDATE ( )
Tipo de valor devuelto
datetime
no smalldatetime
Here is more detail explain of the SQL Server Error Messages - Msg 298
Related
After upgrading from SQL Server 2012 to SQL Server 2017 a stored procedure feeding a quarterly report is failing to provide information. Identified the issue as the procedure is failing to generate a variable that drives the rest of the procedure.
Identified the variable wasn't being set due to a CONVERT statement using the data style NULL. If the query below is run on SQL Server 2017 the variable #CountFrequency returns NULL, as expected based on the Microsoft Doc regarding CONVERT and data style NULL. If that query is run on SQL Server 2012 or 2016 #CountFrequency returns 4, which allowed the stored procedure to run successfully in our production environment prior to the upgrade.
DECLARE #OwnerCountUDF varchar(30) = '4'
, #CountFrequency int
;
IF ISNUMERIC(#OwnerCountUDF) = 1
SELECT #CountFrequency = CONVERT(int,#OwnerCountUDF,NULL)
ELSE
SELECT #CountFrequency = 1
;
SELECT ISNUMERIC(#OwnerCountUDF) 'Numeric'
, #OwnerCountUDF '#OwnerCountUDF'
, #CountFrequency '#CountFrequency'
;
Have been unable to find any documentation about a change to CONVERT which would cause this difference in results.
According to the documentation, which is annotated SQL Server (starting with 2008):
style
An integer expression that specifies how the CONVERT function will translate expression. For a style value of NULL, NULL is returned. data_type determines the range.
Perhaps your compatibility level was set to an even earlier version in the SQL Server 2012 version.
I'm trying to write my existing tables to files and save it locally.
I'm using T-SQL with SQuirrel JDBC Connection to Sybase
I tried the following Code to write results into a file:
SELECT * FROM date_dimension;
OUTPUT TO "C:\Users\temp\output.txt" FORMAT ASCII;
I dont know why it doesn't work but I get a Syntax error while trying this.
Error: SQL Anywhere Error -131: Syntax error near 'OUTPUT' on line 1
SQLState: 42W04
ErrorCode: 102
Can someone see a mistake in the code? Is there another way to write into file from Sybase IQ?
I'm new to all this Tools and I'm sry for such a question
Please help me :)
CREATE TABLE DATE_DIMENSION
( [DateKey] INT primary key,
[Date] DATETIME,
[FullDateUK] CHAR(10), -- Date in dd-MM-yyyy format
[FullDateUSA] CHAR(10),-- Date in MM-dd-yyyy format
}
That should work, your syntax is correct, can you provide the ddl of the table?
Edit: try this select statement:
select DateKey,("Date"),FullDateUK,FullDateUSA from DATE_DIMENSION;
OUTPUT TO "C:\Users\temp\output.txt" FORMAT ASCII;
[Using SQL Server 2008 R2 Enterprise x64 SP1]
I am trying to use some form of GETDATE() to pass today's date to a stored procedure inside OPENQUERY(), but I keep getting the error
Msg 8114, Level 16, State 1, Procedure spCalcProjection, Line 0
Error converting data type nvarchar to datetime
Here is the code (spCalcProjection takes a datetime):
SELECT top 1 multi FROM OPENQUERY([production], 'exec proddb.dbo.spCalcProjection "GETDATE()"')
If I use 2014-05-22 or any literal in place of GETDATE() then I have no problem and get the correct, expected result. If I use some other functionality like CAST(GETDATE() AS DATE) or CONVERT(varchar, GETDATE(), 112) then I get the above error again.
Conrad, posting original syntax error for GETDATE() without double quotes could help more than you think. I also don't see why would you need to escape the function here. (Sorry, can't add to your thread with Lamak, not enough reputation for comments). Also, why do you need an open query to call your sp? When you say SQL Server 2008 R2, is it both on the calling side and on your [production] server? If the other end is not SQL Server it might not have GETDATE() function. If the other end is SQL Server you don't need OpenQuery.
[UPDATE]
I think I have your answer. You cannot use a function as a parameter for stored procedure. Has nothing to do with open query. What you can do, you can replace that stored procedure with table-valued function. I just tried it and it worked.
Definition:
CREATE FUNCTION TestFun
(
#TestDateParam datetime
)
RETURNS
#RetTable TABLE
(
Line nvarchar(20)
)
AS
BEGIN
INSERT INTO #RetTable
SELECT aString
FROM sometable
WHERE aDate = #TestDateParam
RETURN
END
Call:
SELECT *
FROM dbname.dbo.TestFun(GETDATE())
Got an answer from elsewhere that I will use:
SELECT top 1 multi FROM OPENQUERY([production], 'DECLARE #dt datetime SELECT #dt = GETDATE() exec proddb.dbo.spCalcProjection #dt')
This avoids having to create any additional objects in the db.
I am looking to pass a date variable from Access to a SQL Server stored procedure. Please see my code:
VBA:
searchDate = 03/07/2014
cmd.Parameters.Append _
cmd.CreateParameter("#searchDate", adDBTimeStamp, adParamInput, , searchDate)
searchDate is a date formatted as MM/DD/YYYY
SQL:
ALTER PROCEDURE [dbo].[spAppendActivity]
#searchDate as datetime,
AS
SET NOCOUNT ON;
delete * from tbl_activity_losses;
select [Date]
into tbl_activity_losses
from tbl_master_rec
where [Date] = #searchDate
I get an ODBC error stating
[Microsoft][ODBC SQL Server Driver] Conversion failed when converting date and/or time from character string.
Any help on how to pass this date field to my stored procedure would be greatly appreciated.
The problem is adDBTimeStamp. It is converting your simple date string into a timestamp. (NOT a date)
When that timestamp is passed to your stored procedure, SQL server has no idea how to turn that long string into a date.
Changing the type from adDBTimeStamp to adVarChar will keep it as a string and SQL Server will know how to parse it properly.
Additionally, you can change your stored procedure type from DateTime to varchar as well. SQL Server will know how to parse that into a date.
I have an data base (.mdb) and it has a column with dates (dd/mm/yy) , some one give me a code to get all the dates in database between 2 dates , the code was :
Select * from table where date between 'StartDate' and 'EndDate'
but after I use the code , an error occurs told me that the types of data is not the same
System.Data.OleDb.OleDbException was
unhandled ErrorCode=-2147217913
Message="عدم تطابق نوع البيانات في
تعبير المعايير." Source="Microsoft
JET Database Engine"
although I convert the data type in the column of dates in database to (Date \ time) , and use OLE object to connect to data base
what is wrong , and what I have to do ?
You usually need to surround date/time types with # when working with Access, like so
#22/01/2009#
Instead of using dynamic SQL, instead use the Access Database Engine's CREATE PROCEDURE SQL DDL syntax to create a persisted object whose parameters have parameters strongly-typed as DATETIME with the NULL value as default. Handle the NULL value to use the DATETIME column's value instead e.g.
CREATE PROCEDURE GetStuff
(
arg_start_date DATETIME = NULL,
arg_end_date DATETIME = NULL
)
AS
SELECT lastvstart
FROM tb
WHERE lastvstart
BETWEEN IIF(arg_start_date IS NULL, lastvstart, arg_start_date)
AND IIF(arg_end_date IS NULL, lastvstart, arg_end_date);