Avatar of sparker1970
sparker1970
Flag for United States of America asked on

Query Syntax in SSMS

I have a query I am trying to write and I have a couple of issues retrieving data:

Issue #1: I am trying to return the right 2 characters in a field that appears to be left justified. The field is a combined 'CITY ST' with a space delimiter before the 2 character state. I obviously cannot determine precisely where in that 50 character, left justified field the actual 2 characters will be.

Issue #2: I am trying to write an expression that I did have working in an Access database (I am trying to move my queries to management studio). The query in Access was:

Round([PER_DIEM_INT]+(Round((GETDATE()-[PER_DIEM_DATE])*[PER_DIEM_AMT],2)),2)-[INT_COLL] AS INT_DUE

error: Implicit conversion from data type datetime to float is not allowed. Use the CONVERT function to run this query.
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
sparker1970

8/22/2022 - Mon
SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PortletPaul

try this for #2
ROUND( [PER_DIEM_INT] + ROUND( DATEDIFF(day,PER_DIEM_DATE, GETDATE() ) *[PER_DIEM_AMT] ,2) )

Think you need to use DATEDIFF() this returns an integer number of the units (I chose day as the unit)

Issue #1. Are you saying the state isn't always at the last 2 chars at the right?
ASKER CERTIFIED SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sparker1970

ASKER
Paul...with the 2 "ROUND" statements there was a missing argument for one of them.

St. Jimbo...the RTRIM statement worked perfectly...your "wild guess" was spot on with one exception, it was day not days.
sparker1970

ASKER
See my last post for response on solutions.

Thank you very much!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23