A small free .Net and JS library (with demo UI, command-line bulk formatter, SSMS/VS add-in, notepad++ plugin, winmerge plugin, and demo webpage) for reformatting and coloring T-SQL code to the user's preferences.
select a.visit_date,
a.hourid,
case
when A.device_id is not null
and a.tag = 1
then a.puid
else null
end as puid,
a.puid_type as puid_type,
case
when a.device_id is not null
and a.tag = 1
then 2
else 1
end as user_type,
a.province_id as province_id,
a.province_name as province_name,
a.city_id as city_id,
a.city_name as city_name,
a.term_type_id as term_type_id,
a.term_prod_id as term_prod_id,
a.portal_id as portal_id,
a.tpa as tpa,
a.tpa_type as tpa_type,
a.msisdn,
a.imei,
a.idfa,
a.cookie,
a.access_media,
a.channel_id,
a.ip,
a.page_url,
a.page_id,
a.program_id,
nvl (a.content_id, b.content_id) as content_id,
a.version_id_8,
null as is_from_imei,
a.pv
from tmp_video_active_tourist a;
Here's what I want the formatting to look like
SELECT a.visit_date,
a.hourid,
CASE
WHEN A.device_id IS NOT NULL
AND a.tag = 1
THEN a.puid
ELSE NULL
END AS puid,
a.puid_type AS puid_type,
CASE
WHEN a.device_id IS NOT NULL
AND a.tag = 1
THEN 2
ELSE 1
END AS user_type,
a.province_id AS province_id,
a.province_name AS province_name,
a.city_id AS city_id,
a.city_name AS city_name,
a.term_type_id AS term_type_id,
a.term_prod_id AS term_prod_id,
a.portal_id AS portal_id,
a.tpa AS tpa,
a.tpa_type AS tpa_type,
a.msisdn,
a.imei,
a.idfa,
a.cookie,
a.access_media,
a.channel_id,
a.ip,
a.page_url,
a.page_id,
a.program_id,
nvl(a.content_id, b.content_id) AS content_id,
a.version_id_8,
NULL AS is_from_imei,
a.pv
FROM tmp_video_active_tourist a;
I use "PoorMansTSqlFormatterDemo" formatting SQL.
Here is the code before formatting.
Here's what I want the formatting to look like