I am working on a requirement where I need to get unique records count from one table with like search on the columns.
Here is the code:
Select
s1.so_number
from
(
Select (billto_name) As so_number
from dbo.lamp_bookings
where billto_name Like '%government%' or billto_name Like '%gov%'
Union
Select (shipto_name) As so_number
from dbo.lamp_bookings
where shipto_name Like '%government%' or shipto_name Like '%gov%'
Union
Select (soldto_name) As so_number
from dbo.lamp_bookings
where soldto_name Like '%government%' or soldto_name Like '%gov%'
Union
Select (end_user) As so_number
from dbo.lamp_bookings
where end_user Like '%government%' or end_user Like '%gov%'
) s1
I need to get distinct count from bookings either soldto_name or shipto_name or billto_name or end_user like (government, govt.,)
sql serversince they includeddbo. With that said, sample data and expected results would be very helpful.COUNT (DISTINCT s1.so_number).LIKE '%government%'also matchesLIKE '%gov%'. You can shorten youWHEREclauses toWHERE <column> LIKE '%gov%'.