Saturday, September 28, 2019

SQL Server - Different types Formatting of Date/Time with Example


MM/DD/YYYY to YYYY/MM/DD

Declare @DateFormat varchar(20)
set @DateFormat='02/21/2019' --MM/DD/YYYY
Select @DateFormat as SourceFormat, CONVERT(Date,@DateFormat,101) as TargetFormat

SourceFormat   TargetFormat
02/21/2019         2019-02-21

DD/MM/YYYY to YYYY/MM/DD

Declare @DateFormat varchar(20)
set @DateFormat='24/02/2019' --DD/MM/YYYY
Select @DateFormat as SourceFormat, CONVERT(Date,@DateFormat,103) as TargetFormat

SourceFormat   TargetFormat
24/02/2019         2019-02-24

YYYY/MM/DD to DD/MM/YYYY

Declare @DateFormat varchar(20)
set @DateFormat='2019/05/24' --YYYY/MM/DD
Select @DateFormat as SourceFormat, CONVERT(VARCHAR(10), CAST(@DateFormat AS DATETIME), 103) as TargetFormat

SourceFormat   TargetFormat
2019/05/24         24/05/2019


DD/MM/YYYY to MM/DD/YYYY

Declare @DateFormat varchar(20)
set @DateFormat='20/05/2019' --DD/MM/YYYY
Select @DateFormat as SourceFormat, convert(varchar, convert(date, @DateFormat, 105), 101) as TargetFormat

SourceFormat   TargetFormat
20/05/2019         05/20/2019

MM-DD-YYYY to DD-MM-YYYY

Declare @DateFormat varchar(20)
set @DateFormat='05-24-2019' --MM-DD-YYYY
Select @DateFormat as SourceFormat, convert(varchar, convert(date, @DateFormat, 101), 105) as TargetFormat

SourceFormat   TargetFormat
05-24-2019          24-05-2019

Tuesday, September 24, 2019

Display Database Images in SSRS Report


Follow the below steps to display database images in SSRS Reports.

I have used AdventureWorksDW2017 database for the below example.

Create the dataset using the below sql script

select FirstName+' '+LastName as EmployeeName,Title as EmployeeTitle,EmailAddress,DepartmentName,EmployeePhoto
from DimEmployee


Create a table in report body and do the formatting.

Click on the text box property-> Insert->Image
Select Image source->Database
User this Field->Column Name (EmployeePhoto)

For detailed video click below: