USE [BlueDot]
GO
/****** Object: StoredProcedure [dbo].[report_basic_cases_06_results] Script Date: 07/31/2016 20:17:44 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[report_basic_cases_06_results]
(
@userid VARCHAR(MAX),
@start_date DATE = NULL,
@end_date DATE = NULL,
@tags VARCHAR(MAX) = NULL ,
@keyword VARCHAR(250)= NULL
)
AS
SELECT
a.CaseID ,
a.Visible ,
a.Updatedby ,
a.Lastupdate ,
a.SectionCase ,
a.FirmId ,
a.Importance ,
a.VisibleEmployer ,
a.tags,
b.UserId AS attyid ,
b.MailStr + ' ' + b.MaidenNm AS atty ,
c.id,
c.CaseId ,
c.Archived ,
d.FirstNm + ' ' + d.LastNm AS Alien,
g.description AS casestatus,
a.Comments
FROM dbo.Casecomments a
LEFT JOIN Users AS b ON b.UserId = a.Updatedby
INNER JOIN Cases AS c ON c.Id = a.CaseID
INNER JOIN Users AS d ON d.UserId = c.AlienId
INNER JOIN Cases AS h ON h.id = a.caseid
INNER JOIN admin_casestatus AS g ON h.Archived = g.idstatus
WHERE a.SectionCase = 'Case'
AND c.Archived <> 1
AND a.Updatedby LIKE @userid
AND (@start_date is null or a.Lastupdate >= @start_date) and (@end_date is null or a.Lastupdate < dateadd(d,1,@end_date))
AND ( @tags IS NULL OR @tags = '' OR a.tags IN (SELECT value FROM dbo.Split(@tags, ',')))
AND ((RTRIM(@keyword) IS NULL) OR (a.Comments LIKE '%' + @keyword + '%'))
ORDER BY a.Lastupdate DESC;
Dim sp_reporting__userid
sp_reporting__userid = ""
if(request.form("userid") <> "") then sp_reporting__userid = request.form("userid")
Dim sp_reporting__start_date
sp_reporting__start_date = null
if(request.form("comment_start") <> "") then sp_reporting__start_date = request.form("comment_start")
Dim sp_reporting__end_date
sp_reporting__end_date = null
if(request.form("comment_end") <> "") then sp_reporting__end_date = request.form("comment_end")
Dim sp_reporting__tags
sp_reporting__tags = ""
if(request.form("tags") <> "") then sp_reporting__tags = request.form("tags")
Dim sp_reporting__keyword
sp_reporting__keyword = null
if(request.form("keyword") <> "") then sp_reporting__keyword = request.form("keyword")
%>
<%
set sp_reporting = Server.CreateObject("ADODB.Command")
sp_reporting.ActiveConnection = MM_bluedot_STRING
sp_reporting.CommandText = "dbo.report_basic_cases_06_results"
sp_reporting.Parameters.Append sp_reporting.CreateParameter("@RETURN_VALUE", 3, 4)
sp_reporting.Parameters.Append sp_reporting.CreateParameter("@userid", 200, 1,500,sp_reporting__userid)
sp_reporting.Parameters.Append sp_reporting.CreateParameter("@start_date", 135, 1,10,sp_reporting__start_date)
sp_reporting.Parameters.Append sp_reporting.CreateParameter("@end_date", 135, 1,10,sp_reporting__end_date)
sp_reporting.Parameters.Append sp_reporting.CreateParameter("@tags", 200, 1,5000,sp_reporting__tags)
sp_reporting.Parameters.Append sp_reporting.CreateParameter("@keyword", 200, 1,100,sp_reporting__keyword)
sp_reporting.CommandType = 4
sp_reporting.CommandTimeout = 0
sp_reporting.Prepared = true
set report_results = sp_reporting.Execute
report_results_numRows = 0
( @tags IS NULL OR @tags = '' OR exists (
select count(*) from dbo.Split(a.tags, ',') as tbl
join (SELECT value FROM dbo.Split(@tags, ',')) as web
on tbl.value = web.value
having count(*) > 0
))
USE [BlueDot]
GO
/****** Object: UserDefinedFunction [dbo].[Split] Script Date: 07/31/2016 22:08:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[Split] (@list nvarchar(max), @delim nchar(1) = ',')
returns table as
return
with csvtbl(start, [stop]) as (
select start = convert(bigint, 1), [stop] = charindex(@delim collate slovenian_bin2, @list + @delim)
union all
select start = [stop] + 1, [stop] = charindex(@delim collate slovenian_bin2, @list + @delim, [stop] + 1)
from csvtbl
where [stop] > 0
)
select ltrim(rtrim(substring(@list, start, case when [stop] > 0 then [stop] - start else 0 end))) as value
from csvtbl
where ([stop] > 0)
and (ltrim(rtrim(substring(@list, start, case when [stop] > 0 then [stop] - start else 0 end))) <> '')
Msg 102, Level 15, State 1, Procedure report_basic_cases_06_results, Line 43
Incorrect syntax near '.'.
Msg 156, Level 15, State 1, Procedure report_basic_cases_06_results, Line 44
Incorrect syntax near the keyword 'as'.
USE [BlueDot]
GO
/****** Object: StoredProcedure [dbo].[report_basic_cases_06_results] Script Date: 07/31/2016 20:17:44 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[report_basic_cases_06_results]
(
@userid VARCHAR(MAX),
@start_date DATE = NULL,
@end_date DATE = NULL,
@tags VARCHAR(MAX) = NULL ,
@keyword VARCHAR(250)= NULL
)
AS
SELECT
a.CaseID ,
a.Visible ,
a.Updatedby ,
a.Lastupdate ,
a.SectionCase ,
a.FirmId ,
a.Importance ,
a.VisibleEmployer ,
a.tags,
b.UserId AS attyid ,
b.MailStr + ' ' + b.MaidenNm AS atty ,
c.id,
c.CaseId ,
c.Archived ,
d.FirstNm + ' ' + d.LastNm AS Alien,
g.description AS casestatus,
a.Comments
FROM dbo.Casecomments a
LEFT JOIN Users AS b ON b.UserId = a.Updatedby
INNER JOIN Cases AS c ON c.Id = a.CaseID
INNER JOIN Users AS d ON d.UserId = c.AlienId
INNER JOIN Cases AS h ON h.id = a.caseid
INNER JOIN admin_casestatus AS g ON h.Archived = g.idstatus
WHERE a.SectionCase = 'Case'
AND c.Archived <> 1
AND a.Updatedby LIKE @userid
AND (@start_date is null or a.Lastupdate >= @start_date) and (@end_date is null or a.Lastupdate < dateadd(d,1,@end_date))
AND ( @tags IS NULL OR @tags = '' OR exists (select count(*) from dbo.Split(a.tags, ',') as tbl JOIN (SELECT value FROM dbo.Split(@tags, ',')) as web on tbl.value = web.value HAVING count(*) > 0))
AND ((RTRIM(@keyword) IS NULL) OR (a.Comments LIKE '%' + @keyword + '%'))
ORDER BY a.Lastupdate DESC;
USE [BlueDot]
GO
/****** Object: StoredProcedure [dbo].[report_basic_cases_06_results] Script Date: 07/31/2016 20:17:44 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[report_basic_cases_06_results]
(
@userid VARCHAR(MAX),
@start_date DATE = NULL,
@end_date DATE = NULL,
@tags VARCHAR(MAX) = NULL ,
@keyword VARCHAR(250)= NULL
)
AS
SELECT
a.CaseID ,
a.Visible ,
a.Updatedby ,
a.Lastupdate ,
a.SectionCase ,
a.FirmId ,
a.Importance ,
a.VisibleEmployer ,
a.tags,
b.UserId AS attyid ,
b.MailStr + ' ' + b.MaidenNm AS atty ,
c.id,
c.CaseId ,
c.Archived ,
d.FirstNm + ' ' + d.LastNm AS Alien,
g.description AS casestatus,
a.Comments
FROM dbo.Casecomments a
LEFT JOIN Users AS b ON b.UserId = a.Updatedby
INNER JOIN Cases AS c ON c.Id = a.CaseID
INNER JOIN Users AS d ON d.UserId = c.AlienId
INNER JOIN Cases AS h ON h.id = a.caseid
INNER JOIN admin_casestatus AS g ON h.Archived = g.idstatus
WHERE a.SectionCase = 'Case'
AND c.Archived <> 1
AND a.Updatedby LIKE @userid
AND (@start_date is null or a.Lastupdate >= @start_date) and (@end_date is null or a.Lastupdate < dateadd(d,1,@end_date))
AND ( @tags IS NULL OR @tags = '' OR exists (select count(*) from dbo.Split(a.tags, ',') as tbl JOIN (SELECT [value] FROM dbo.Split(@tags, ',')) as web on tbl.[value] = web.[value] HAVING count(*) > 0))
AND ((RTRIM(@keyword) IS NULL) OR (a.Comments LIKE '%' + @keyword + '%'))
ORDER BY a.Lastupdate DESC;
Msg 102, Level 15, State 1, Procedure report_basic_cases_06_results, Line 42
Incorrect syntax near '.'.
Msg 156, Level 15, State 1, Procedure report_basic_cases_06_results, Line 42
Incorrect syntax near the keyword 'as'.
declare @tags varchar(50) = 'text3, text2'
select *
from dbo.CaseComments a
where (
@tags IS NULL OR @tags = '' OR
exists (
select count(*) from dbo.Split(a.tags, ',') as tbl JOIN (SELECT [value] FROM dbo.Split(@tags, ',')) as web on tbl.[value] = web.[value] HAVING count(*) > 0
)
)
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near '.'.
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'as'.
declare @tags varchar(50) = 'text3, text2'
select *
from dbo.CaseComments a
where exists (
select count(*) from dbo.Split(a.tags, ',') as tbl
having count(*) > 0
)
DECLARE @tags VARCHAR(50) = 'text3, text2';
SELECT *
FROM dbo.Casecomments a
WHERE EXISTS ( SELECT COUNT(*)
FROM dbo.Split(a.tags, ',') AS tbl
HAVING COUNT(*) > 0 );
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near '.'.
DECLARE @tags VARCHAR(50) = 'text3, text2';
SELECT *
FROM dbo.Casecomments a
WHERE EXISTS ( SELECT COUNT(*)
FROM dbo.Split(@tags, ',') AS tbl
HAVING COUNT(*) > 0 );
DECLARE @tags VARCHAR(50) = 'Travel Date, Contact method';
SELECT *
FROM dbo.Casecomments a
WHERE EXISTS ( SELECT COUNT(*) FROM dbo.Split(@tags, ',') AS tbl HAVING COUNT(*) > 0 )
ORDER BY comid DESC
USE [BlueDot]
GO
/****** Object: Table [dbo].[Casecomments] Script Date: 07/31/2016 23:24:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Casecomments](
[COMID] [INT] IDENTITY(1,1) NOT NULL,
[CaseID] [NUMERIC](18, 0) NULL,
[Visible] [BIT] NULL,
[Comments] [VARCHAR](MAX) NULL,
[Updatedby] [NUMERIC](18, 0) NULL,
[Lastupdate] [DATETIME] NULL,
[CommBy] [BIT] NULL,
[SectionCase] [NVARCHAR](50) NULL,
[FirmId] [INT] NULL,
[Importance] [INT] NULL,
[VisibleEmployer] [BIT] NULL,
[SectionName] [NVARCHAR](50) NULL,
[tags] [NVARCHAR](250) NULL,
CONSTRAINT [PK_Casecomments] PRIMARY KEY CLUSTERED
(
[COMID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Casecomments] ADD CONSTRAINT [DF_Casecomments_Visible] DEFAULT ((0)) FOR [Visible]
GO
ALTER TABLE [dbo].[Casecomments] ADD CONSTRAINT [DF_Casecomments_Lastupdate] DEFAULT (GETDATE()) FOR [Lastupdate]
GO
ALTER TABLE [dbo].[Casecomments] ADD CONSTRAINT [DF_Casecomments_CommBy] DEFAULT ((0)) FOR [CommBy]
GO
ALTER TABLE [dbo].[Casecomments] ADD CONSTRAINT [DF_Casecomments_SectionCase] DEFAULT (N'Case') FOR [SectionCase]
GO
select a.COMID, a.CaseID, s.[value]
from dbo.Casecomments as a
cross apply dbo.Split (a.tags, ',') s
If that is right, then you shouldn't be using the "a.tags IN (SELECT value FROM dbo.Split(@tags, ','))" portion of code.
Let's say that the user chose two tags to filter his query: text1 and text2. Your IN clause, as currently constructed, says, "Is 'text1,text2,text3' in 'text1'?" No. Then, "Is 'text1,text2,text3' in 'text2'?" And again the answer is no.
In other words, you are treating 'text1,text2,text3' as one value, then trying to compare that one composite value to individual values like 'text1' then 'text2'. That won't work. Does what I'm writing make sense given what you know about the results you're getting back? Am I missing anything?
Given what I just wrote, I find it hard to believe that things are working correctly for numeric values. I suppose if a.tags contains only *one* value the filter will work, but that doesn't have to do with numeric vs non-numeric. Does that make sense?