Mistři v programování na #hovnokod

SQL #177

select distinct bk.ID, bk.URL, bk.Date, bk.Name, bk.Description, bk.UserCreatorID from bookmarking_bookmark as bk 
where bk.Tenant=@Tenant and bk.ID in 
(select *  from (select b.ID  from bookmarking_bookmark as b  left join  bookmarking_bookmarktag as bt on b.ID=bt.BookmarkID left join bookmarking_tag as t  on bt.TagID=t.TagID 
left join (select ub.BookmarkID as BookmarkID, ub.Name as UserBookmarkName,ub.Description as UserBookmarkDescription, t.Name as TagName  
from (select * from bookmarking_userbookmark as ub where ub.UserID=@userID) as ub 
left join bookmarking_userbookmarktag as ubt  on ub.UserBookmarkID=ubt.UserBookmarkID  
left join bookmarking_tag as t  on ubt.TagID=t.TagID) as ub on b.ID=ub.BookmarkID 
where  ( ( lower(b.URL) like lower(@tagNameForUrlWithoutLastSlash0) )  
or (lower(b.Name) like lower(@tagName0) or lower(b.Name) like lower(@tagNameWithSpace0)) 
or (lower(b.Description) like lower(@tagName0) or lower(b.Description) like lower(@tagNameWithSpace0))    
or (lower(t.Name) like lower(@tagName0)) or (lower(t.Name)  like lower(@tagNameWithSpace0)) 
or (lower(TagName) like lower(@tagName0)) or (lower(TagName) like lower(@tagNameWithSpace0))    
or (lower(UserBookmarkName) like lower(@tagName0) or lower(UserBookmarkName) like lower(@tagNameWithSpace0))    
or (lower(UserBookmarkDescription) like lower(@tagName0) or lower(UserBookmarkDescription) like lower(@tagNameWithSpace0)))  
and b.ID in (
select b.ID   from bookmarking_bookmark as b  left join  bookmarking_bookmarktag as bt  on b.ID=bt.BookmarkID
left join bookmarking_tag as t    on bt.TagID=t.TagID 
left join  (
select ub.BookmarkID as BookmarkID, ub.Name as UserBookmarkName, ub.Description as UserBookmarkDescription, t.Name as TagName from 
(select * from bookmarking_userbookmark as ub where ub.UserID=@userID) as ub  
left join bookmarking_userbookmarktag as ubt on ub.UserBookmarkID=ubt.UserBookmarkID
left join bookmarking_tag as t on ubt.TagID=t.TagID) as ub on b.ID=ub.BookmarkID
where  (( lower(b.URL) like lower(@tagNameForUrlWithoutLastSlash1) ) or (lower(b.Name) like lower(@tagName1) or lower(b.Name) like lower(@tagNameWithSpace1)) 
or (lower(b.Description) like lower(@tagName1) or lower(b.Description) like lower(@tagNameWithSpace1)) or (lower(t.Name) like lower(@tagName1)) 
or (lower(t.Name)  like lower(@tagNameWithSpace1)) or (lower(TagName) like lower(@tagName1)) or (lower(TagName) like lower(@tagNameWithSpace1))  
or (lower(UserBookmarkName) like lower(@tagName1) or lower(UserBookmarkName) like lower(@tagNameWithSpace1)) or (lower(UserBookmarkDescription)
like lower(@tagName1) or lower(UserBookmarkDescription) like lower(@tagNameWithSpace1))) and b.ID in (
select b.ID from bookmarking_bookmark as b left join bookmarking_bookmarktag as bt on b.ID=bt.BookmarkID left join bookmarking_tag as t on bt.TagID=t.TagID left join
(select ub.BookmarkID as BookmarkID, ub.Name as UserBookmarkName,  ub.Description as UserBookmarkDescription, t.Name as TagName 
from (select * from bookmarking_userbookmark as ub where ub.UserID=@userID) as ub 
left join bookmarking_userbookmarktag as ubt on ub.UserBookmarkID=ubt.UserBookmarkID  left join bookmarking_tag as t on ubt.TagID=t.TagID) as ub on b.ID=ub.BookmarkID
where (( lower(b.URL) like lower(@tagNameForUrlWithoutLastSlash2) ) or (lower(b.Name) like lower(@tagName2) or lower(b.Name) like lower(@tagNameWithSpace2))
or (lower(b.Description) like lower(@tagName2) or lower(b.Description) like lower(@tagNameWithSpace2)) or (lower(t.Name) like lower(@tagName2)) or (lower(t.Name)
like lower(@tagNameWithSpace2)) or....

Anonymous,