Friday, August 24, 2018

SQL Server Casting and Format commands

Select       cast('9:30 AM' as time) -- <-- this convert the string into a Time
       format ([First_call],'HH\:mm') --<-- This converts time into 24 hour clock format

Sunday, August 5, 2018

Get the previous dates in SQL server

select dateadd(dd,-x, cast(getdate() as date))
select dateadd(day,-x, cast(getdate() as date))
select dateadd(day,-x, getdate())

-- Replace x with your dates required. x could be - or +

  SELECT DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0)   -- get the month start date

Select EOMONTH(getdate()) -- get last date of the month

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH ...