Richard Housham · Jul 16, 2018

Querying ODBC SQL Server

Hi I've got a service setup to query a sql server via ODBC.

I've got all the parameters etc setup and everything is ok

My Query is

MaritalStatus AS MartialStatusCode,
(SELECT CodeDescription FROM GenMaritalStatus WHERE Code =  MaritalStatus) AS Martial,
Ethnicity AS EnthnicityCode,
(SELECT CodeDescription FROM GenEthnicity WHERE Code = Ethnicity) AS Ethnicity,
Nationality AS NationalityCode,
(SELECT CodeDescription FROM GenNationality WHERE Code = Nationality) AS Nationality,
CN.Surname AS Surname,
 ISNULL (CN.GivenName1, '')
 + ISNULL( CN.GivenName2, '')
 + ISNULL(CN.GivenName3, '')
 + ISNULL( CN.GivenName4, '')
 + ISNULL(CN.GivenName5, '') AS Forename,
 ISNULL(CN.Prefix, '' ) AS Title,
  FROM [ClientIndex] CI
  INNER JOIN ClientName CN ON CI.ClientID = CN.ClientID WHERE LastUpdated > ?
ORDER BY LastUpdated

If I have my parameter as  

Do ..Adapter.SetPersistentValue(..%ConfigName,"LastModified","20080915")

This works. 

But if I add in the time part like this.

Do ..Adapter.SetPersistentValue(..%ConfigName,"LastModified","20080915 10:00:00")

I get 
ERROR #6022: Gateway failed: Execute. + ERROR <Ens>ErrGeneral: SQLState: (22001) NativeError: [0] Message: [Microsoft][ODBC SQL Server Driver]String data, right truncation

I've tried lots of different date/time formats but nothing seems to work. 

I've got a odbc sql browser and that works with this date format (yyyymmdd HH:ii:ss) 

So what gives here?



1 1,443
Discussion (11)3
Log in or sign up to continue

Your SetPersistentValue calls refer to LastModified, but your query refers to LastUpdated. Is this a typo in your post?

If you use Portal (Explorer, SQL) to run a query that reports LastUpdated values, what do they look like? More technically, what datatype are they?

Hi yeah, I could have them all the same name.  But not sure if it'll make any difference.
(I'll give it a go though).

With regards data type LastUpdated  is a datetime in SQL Server 2008 .

I've tried to get a more updated driver see if that would help (no). I also read some stuff here on C and odbc issues.

If I remember correctly ensemble/healthshare has a C 'core' does it not?

Huh, renamed the variables and seems a bit more compliant/working. 
Need to test it out but might have a winner!

Nope my mistake, messed up my variables when renaming. Got them all ok now and still errors.

If you use Portal (Explorer, SQL) to run a query that reports LastUpdated values

It's an odbc connection so it's not in the explorer > SQL

Had a look, almost got it but then got this.

 [SQLCODE: <-226>:<Gateway query Execute() failed>]

  [%msg: <Connection 'xxxxx': Execute: SQLState: (22018) NativeError: [0] Message: [Microsoft][ODBC Driver 11 for SQL Server]Invalid character value for cast specification >]

Yeah, it's not happy.

I've thrown this one to WRC who are looking at it. 

what about using real ODBC datetime format  "2008-09-15 10:00:00" ?

Using this format ( "2008-09-15 10:00:00" ) solved my issues with calling a stored procedure using ..Adapter.ExecuteProcedure

Hi Martin !

I am having the same problem with ODBC and SQL Server. Can you please show me an example of your ExecuteProcedure syntax?

For example :

Do you use ..Adapter.ExecuteProcedure ( PROCEDURE_NAME '2022-01-01 00:00:00', '2022-01-10 23:59:00') syntax ?  I mean, do you ' as separators? 

Thanks in advance...