'Handling SQL join via timezone
I need to join two tables. The join has to be handled using parameter @timezone. But there is a catch - @timezone's value can be null, '', ' ' or anything else. User can enter everything.
If @timezone's value is null the outcome of the join will be basically nothing. So that, if it happens, there has to be at least basic value to join (for example, 'Pacific Standard Time')
DECLARE @StartDate DATE = '2022-01-20', @EndDate DATE = '2022-01-30', @t1 INT = 12345, @timezone VARCHAR(max) = NULL, @OnlyActivated INT = 0
SELECT r.ChargeType, r.CustomerName, r.PurchaseDate, r.accountID
FROM table_report as r
LEFT JOIN [sys].[time_zone_info] tzi ON tzi.[name] = @timezone (???)
I tried IIF(@timezone IN (NULL,'',' '),'Pacific Standard Time',@timezone) and it worked with '' and ' ' scenarios but then I realized that null can't be compared.
Maybe there is a pretty obvious solution but I don't see it.
Hope you can help with that.
P.S. CURRENT_TIMEZONE_ID() is not supported.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
