Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag for Australia

asked on

How does this SELECT query work

Heyas,

Can someone explain to me how the second line of this query works ({Date:Incidents} {Field:Site:General} {Field:Location:General} ) as I have never seen this with a SELECT statement beforehand:

select count(*) from vwReg_Incidents_Posted where (datediff(dd, IncidentDate, DateFirstPosted) <=
3) 
{Date:Incidents} {Field:Site:General} {Field:Location:General}  

Open in new window


I am running SQL Server 2008 R2.

Any assistance is welcome.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zack

ASKER

Thank you sir reading up now.
SOLUTION
Avatar of Nakul Vachhrajani
Nakul Vachhrajani
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree to Nakul, this is no standard syntax, and has to be handled by the application using the query.
Hi Zack,
Below is working perfectly for me.. <<Check the where clause comparision>>

WHERE N =  { d '2016-01-01' }

DECLARE @Start AS DATE = '2016/01/01'

;WITH SingleDigits(Number) AS
(
    SELECT Number
    FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8),
    (9), (0)) AS X(Number)
)
,Series AS
(
    SELECT (d1.Number+1) + (10*d2.Number) Number
    from
    SingleDigits as d1,
    SingleDigits as d2    
)
SELECT * FROM 
(
	SELECT DATEADD(MONTH , Number-1 , @Start) N FROM Series 
	WHERE Number <= 12
)x WHERE N =  { d '2016-01-01' } 

Open in new window


Output

N
----------
2016-01-01

(1 row(s) affected)

Open in new window


Hope it helps !
Avatar of Zack

ASKER

Thank you for the additional info, both the comments you provided give me the complete picture of what I am looking at.
Avatar of Zack

ASKER

Hi Qlemo,

Pawan comment is relevant because when I run the query in SSMS with the following line at the end ({Date:Incidents} {Field:Site:General} {Field:Location:General} )  it gives an error. However when I run the complete query inside a 'bespoke software solution' we have called R-Base it works just fine.  Then I queried with the developer about how this line was working in the software {Date:Incidents} {Field:Site:General} {Field:Location:General} giving him Pawan link. He confirmed that's how the software was working.

Thank you and merry christmas.
That doesn't make sense to me, sorry, but you'll have to take the developer's word for it ...
I fail to understand as well. The tags ({Date:Incidents} {Field:Site:General} {Field:Location:General}) are definitely not ODBC standard.

As clearly mentioned on the first line of the link (https://msdn.microsoft.com/en-us/library/ms712360(v=VS.85).aspx), the ODBC escape sequences are only for literals of specific data types:

"ODBC defines escape sequences for date, time, and timestamp literals."