Querying ODBC SQL Server

Primary tabs

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

SELECT TOP 1
CI.ClientID, 
Gender, 
DateOfBirth, 
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,
DateOfDeath,
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,
 LastUpdated
  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?

Thanks

Richard

  • 0
  • 1
  • 310
  • 9
  • 0

Comments

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.
https://docs.microsoft.com/en-us/sql/relational-databases/native-client-...

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.

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