SQL Server hangs - sql-server

I'm training on SQL Server 2012 and I had no problem till today. It suddenly started hanging when trying to create new database, backup a database or basically almost any option that involves databases. If I switch instance everything works fine. When I choose the create database option for example it just loads for about 3-4mins then stops loading like nothing happened and brings up the "new database" window 5mins later. I tried tracking the queries running with server profiler but they don't make any sense really. The only process I managed to find that took 218 secs was the one in this picture. I've also attached the code of that query if it makes any sense.
exec sp_executesql N'
create table #tempbackup (database_name nvarchar(128), [type] char(1), backup_finish_date datetime)
insert into #tempbackup select database_name, [type], max(backup_finish_date) from msdb..backupset where [type] = ''D'' or [type] = ''L'' or [type]=''I'' group by database_name, [type]
create table #tmp_sp_db_vardecimal_storage_format (dbname sysname null, vardecimal_enabled varchar(3) null)
if exists (select o.object_id from sys.system_objects o where o.name=N''sp_db_vardecimal_storage_format'')
begin
insert into #tmp_sp_db_vardecimal_storage_format exec sys.sp_db_vardecimal_storage_format
end
DECLARE #is_policy_automation_enabled bit
SET #is_policy_automation_enabled = (SELECT CONVERT(bit, current_value)
FROM msdb.dbo.syspolicy_configuration
WHERE name = ''Enabled'')
create table #tmp_db_hadr_dbrs (group_database_id uniqueidentifier, synchronization_state tinyint, is_local bit)
declare #HasViewPermission int
select #HasViewPermission = HAS_PERMS_BY_NAME(null, null, ''VIEW SERVER STATE'')
if (#HasViewPermission = 1)
begin
insert into #tmp_db_hadr_dbrs select group_database_id, synchronization_state, is_local from master.sys.dm_hadr_database_replica_states
end
SELECT
dtb.name AS [Name],
(select count(*) from master.dbo.sysprocesses p where dtb.database_id=p.dbid) AS [ActiveConnections],
dtb.is_auto_close_on AS [AutoClose],
dtb.is_auto_shrink_on AS [AutoShrink],
dtb.compatibility_level AS [CompatibilityLevel],
dtb.create_date AS [CreateDate],
CAST(0 AS float) AS [DataSpaceUsage],
CAST(0 AS bit) AS [DboLogin],
N'''' AS [DefaultFileGroup],
'''' AS [DefaultSchema],
dtb.database_id AS [ID],
CAST(0 AS float) AS [IndexSpaceUsage],
CAST(has_dbaccess(dtb.name) AS bit) AS [IsAccessible],
CAST(0 AS bit) AS [IsDbAccessAdmin],
CAST(0 AS bit) AS [IsDbBackupOperator],
CAST(0 AS bit) AS [IsDbDatareader],
CAST(0 AS bit) AS [IsDbDatawriter],
CAST(0 AS bit) AS [IsDbDdlAdmin],
CAST(0 AS bit) AS [IsDbDenyDatareader],
CAST(0 AS bit) AS [IsDbDenyDatawriter],
CAST(0 AS bit) AS [IsDbOwner],
CAST(0 AS bit) AS [IsDbSecurityAdmin],
dtb.is_fulltext_enabled AS [IsFullTextEnabled],
CAST(case when dtb.name in (''master'',''model'',''msdb'',''tempdb'') then 1 else dtb.is_distributor end AS bit) AS [IsSystemObject],
suser_sname(dtb.owner_sid) AS [Owner],
ISNULL(df.physical_name, N'''') AS [PrimaryFilePath],
(dtb.is_published*1+dtb.is_subscribed*2+dtb.is_merge_published*4) AS [ReplicationOptions],
CAST(0 AS float) AS [Size],
CAST(0 AS float) AS [SpaceAvailable],
case
when dtb.collation_name is null then 0x200
else 0
end |
case
when 1 = dtb.is_in_standby then 0x40
else 0
end |
case dtb.state
when 1 then 0x2
when 2 then 0x8
when 3 then 0x4
when 4 then 0x10
when 5 then 0x100
when 6 then 0x20
else 1
end
AS [Status],
'''' AS [UserName],
dtb.is_ansi_null_default_on AS [AnsiNullDefault],
dtb.is_ansi_nulls_on AS [AnsiNullsEnabled],
dtb.is_ansi_padding_on AS [AnsiPaddingEnabled],
dtb.is_ansi_warnings_on AS [AnsiWarningsEnabled],
dtb.is_arithabort_on AS [ArithmeticAbortEnabled],
dtb.is_auto_create_stats_on AS [AutoCreateStatisticsEnabled],
dtb.is_auto_update_stats_on AS [AutoUpdateStatisticsEnabled],
CAST(CHARINDEX(N''_CS_'', dtb.collation_name) AS bit) AS [CaseSensitive],
dtb.is_cursor_close_on_commit_on AS [CloseCursorsOnCommitEnabled],
dtb.collation_name AS [Collation],
dtb.is_concat_null_yields_null_on AS [ConcatenateNullYieldsNull],
dtb.is_db_chaining_on AS [DatabaseOwnershipChaining],
CAST(( case LOWER(convert( nvarchar(128), DATABASEPROPERTYEX(dtb.name, ''Updateability''))) when ''read_write'' then 1 else 0 end) AS bit) AS [IsUpdateable],
(select backup_finish_date from #tempbackup where type = #_msparam_0 and db_id(database_name) = dtb.database_id) AS [LastBackupDate],
(select backup_finish_date from #tempbackup where type = #_msparam_1 and db_id(database_name) = dtb.database_id) AS [LastDifferentialBackupDate],
(select backup_finish_date from #tempbackup where type = #_msparam_2 and db_id(database_name) = dtb.database_id) AS [LastLogBackupDate],
dtb.is_local_cursor_default AS [LocalCursorsDefault],
dtb.is_numeric_roundabort_on AS [NumericRoundAbortEnabled],
dtb.page_verify_option AS [PageVerify],
dtb.is_quoted_identifier_on AS [QuotedIdentifiersEnabled],
dtb.is_read_only AS [ReadOnly],
dtb.recovery_model AS [RecoveryModel],
dtb.is_recursive_triggers_on AS [RecursiveTriggersEnabled],
dtb.user_access AS [UserAccess],
CAST(DATABASEPROPERTYEX(dtb.name, ''Version'') AS int) AS [Version],
dtb.is_auto_update_stats_async_on AS [AutoUpdateStatisticsAsync],
dtb.is_broker_enabled AS [BrokerEnabled],
drs.database_guid AS [DatabaseGuid],
ISNULL(DB_NAME(dtb.source_database_id), N'''') AS [DatabaseSnapshotBaseName],
dtb.is_date_correlation_on AS [DateCorrelationOptimization],
ISNULL((select top 1 ftc.name from sys.fulltext_catalogs as ftc where ftc.is_default=1),N'''') AS [DefaultFullTextCatalog],
CAST((case when drs.last_log_backup_lsn is not null then 1 else 0 end) AS bit) AS [HasFullBackup],
CAST(isnull(dtb.source_database_id, 0) AS bit) AS [IsDatabaseSnapshot],
CAST((select count(1) from sys.databases dtbmir where dtbmir.source_database_id = dtb.database_id) AS bit) AS [IsDatabaseSnapshotBase],
0 AS [IsMailHost],
CAST(case when dmi.mirroring_partner_name is null then 0 else 1 end AS bit) AS [IsMirroringEnabled],
dtb.is_parameterization_forced AS [IsParameterizationForced],
dtb.is_read_committed_snapshot_on AS [IsReadCommittedSnapshotOn],
case
when vardec.vardecimal_enabled = ''ON'' then cast(1 as bit)
else cast(0 as bit)
end
AS [IsVarDecimalStorageFormatEnabled],
ISNULL(dtb.log_reuse_wait,0) AS [LogReuseWaitStatus],
ISNULL(dmi.mirroring_failover_lsn,0) AS [MirroringFailoverLogSequenceNumber],
ISNULL(dmi.mirroring_guid,''00000000-0000-0000-0000-0000000000000000'') AS [MirroringID],
ISNULL(dmi.mirroring_partner_name,'''') AS [MirroringPartner],
ISNULL(dmi.mirroring_partner_instance,'''') AS [MirroringPartnerInstance],
ISNULL((case dmi.mirroring_redo_queue_type when N''UNLIMITED'' then 0 else dmi.mirroring_redo_queue end),0) AS [MirroringRedoQueueMaxSize],
ISNULL(dmi.mirroring_role,0) AS [MirroringRole],
ISNULL(dmi.mirroring_role_sequence,0) AS [MirroringRoleSequence],
ISNULL(dmi.mirroring_safety_level + 1, 0) AS [MirroringSafetyLevel],
ISNULL(dmi.mirroring_safety_sequence,0) AS [MirroringSafetySequence],
ISNULL(dmi.mirroring_state + 1, 0) AS [MirroringStatus],
ISNULL(dmi.mirroring_connection_timeout,0) AS [MirroringTimeout],
ISNULL(dmi.mirroring_witness_name,'''') AS [MirroringWitness],
ISNULL(dmi.mirroring_witness_state + 1, 0) AS [MirroringWitnessStatus],
drs.recovery_fork_guid AS [RecoveryForkGuid],
dtb.service_broker_guid AS [ServiceBrokerGuid],
dtb.snapshot_isolation_state AS [SnapshotIsolationState],
dtb.is_trustworthy_on AS [Trustworthy],
CAST(ISNULL(ctb.is_auto_cleanup_on,0) AS bit) AS [ChangeTrackingAutoCleanUp],
CAST(case when ctb.database_id is null then 0 else 1 end AS bit) AS [ChangeTrackingEnabled],
ISNULL(ctb.retention_period,0) AS [ChangeTrackingRetentionPeriod],
CAST(ISNULL(ctb.retention_period_units,0) AS tinyint) AS [ChangeTrackingRetentionPeriodUnits],
N'''' AS [DefaultFileStreamFileGroup],
CAST(dtb.is_encrypted AS bit) AS [EncryptionEnabled],
CAST(ISNULL(dek.database_id, 0) AS bit) AS [HasDatabaseEncryptionKey],
CAST(dtb.is_honor_broker_priority_on AS bit) AS [HonorBrokerPriority],
CAST(0 AS bit) AS [IsManagementDataWarehouse],
case when 1=#is_policy_automation_enabled and exists (select * from msdb.dbo.syspolicy_system_health_state where target_query_expression_with_id like ''Server''+ ''/Database\[#ID='' + convert(nvarchar(20),dtb.database_id) + ''\]%'' ESCAPE ''\'') then 1 else 0 end AS [PolicyHealthState],
dbrs.synchronization_state AS [AvailabilityDatabaseSynchronizationState],
dtb.containment AS [ContainmentType],
dtb.default_fulltext_language_lcid AS [DefaultFullTextLanguageLcid],
ISNULL(dtb.default_fulltext_language_name,N'''') AS [DefaultFullTextLanguageName],
dtb.default_language_lcid AS [DefaultLanguageLcid],
dtb.default_language_name AS [DefaultLanguageName],
ISNULL(fsopt.directory_name , N'''') AS [FilestreamDirectoryName],
ISNULL(fsopt.non_transacted_access , 0) AS [FilestreamNonTransactedAccess],
CAST(dtb.is_nested_triggers_on AS bit) AS [NestedTriggersEnabled],
dtb.target_recovery_time_in_seconds AS [TargetRecoveryTime],
CAST(dtb.is_transform_noise_words_on AS bit) AS [TransformNoiseWords],
dtb.two_digit_year_cutoff AS [TwoDigitYearCutoff],
dtb.name AS [DatabaseName],
dtb.name AS [DatabaseName2],
dtb.containment AS [ContainmentType2]
FROM
master.sys.databases AS dtb
LEFT OUTER JOIN sys.master_files AS df ON df.database_id = dtb.database_id and 1=df.data_space_id and 1 = df.file_id
LEFT OUTER JOIN sys.database_recovery_status AS drs ON drs.database_id = dtb.database_id
LEFT OUTER JOIN sys.database_mirroring AS dmi ON dmi.database_id = dtb.database_id
LEFT OUTER JOIN #tmp_sp_db_vardecimal_storage_format as vardec ON dtb.database_id = db_id(vardec.dbname)
LEFT OUTER JOIN sys.change_tracking_databases AS ctb ON ctb.database_id = dtb.database_id
LEFT OUTER JOIN sys.dm_database_encryption_keys AS dek ON dek.database_id = dtb.database_id
LEFT OUTER JOIN #tmp_db_hadr_dbrs AS dbrs ON dtb.group_database_id = dbrs.group_database_id and dbrs.is_local = 1
LEFT OUTER JOIN sys.database_filestream_options AS fsopt ON fsopt.database_id = dtb.database_id
WHERE
(dtb.name=#_msparam_3)
drop table #tempbackup
drop table #tmp_sp_db_vardecimal_storage_format
drop table #tmp_db_hadr_dbrs
',N'#_msparam_0 nvarchar(4000),#_msparam_1 nvarchar(4000),#_msparam_2 nvarchar(4000),#_msparam_3 nvarchar(4000)',#_msparam_0=N'D',#_msparam_1=N'I',#_msparam_2=N'L',#_msparam_3=N'model'

Related

Using DECLARE while creating a VIEW?

The literature says that the declare statement is not compatible with creating a View. How do I get around it?
My declare statement looks like:
DECLARE #risk_5 TABLE (Code VARCHAR(100));
INSERT INTO #risk_5 (Code) VALUES ('AA'),('BB'),('CC');
and is then used within a select statement:
SELECT
id,
CASE
WHEN a.[10_2_1_Country] IN (SELECT Code from #risk_5)
THEN '3'
END AS Risk_Country5
FROM x
The recommendation is to pack the declare into a CTE or a stored procedure.
With both these recommendations though, I do not understand how to connect the two? What am I missing?
If you need to use variable try to use stored procedures, if you write a select query in the stored procedure you can get the data too. And you can use declare inside.
I use this way in my solution e.g.
CREATE PROCEDURE [dbo].[GetLoadSiteMass]( #month INT,
#year int,
#storageId int,
#parent nvarchar(50),
#materialSourceId nvarchar(100),
#complexIds nvarchar(50))
AS
BEGIN
DECLARE #MonthPrev int
DECLARE #YearPrev int
SET #MonthPrev = CASE WHEN #Month = 1 THEN 12 ELSE #Month - 1 END
SET #YearPrev = CASE WHEN #Month = 1 THEN #Year - 1 ELSE #Year END
declare #WagonLoadSiteId int
set #WagonLoadSiteId = (select top 1 CarriageLoadSiteId from CarriageLoadSite where LoadSiteType = 2);
DECLARE #loadSide nvarchar(10), #result decimal(18,3)
SET #loadSide=cast( #storageId as nvarchar(50));
WITH CarriageLoadSiteTreeView (
[CarriageLoadSiteId],RootId,RootName,[Code], Name, ParentID, [LoadSiteType],IsDelete,
CodeSAP,DepartmentId, Capacity, MinLimit, MaxLimit, LoadSitePlaceTypeId) AS
(
SELECT [CarriageLoadSiteId],
[CarriageLoadSiteId] RootId,
Name RootName,
[Code],
Name,
ParentID,
[LoadSiteType],
[IsDelete],
CodeSAP,
DepartmentId,
Capacity,
MinLimit,
MaxLimit,
LoadSitePlaceTypeId
FROM CarriageLoadSite WITH(NOLOCK)
WHERE ISNULL(ParentID,0) =isnull(#storageId,0) AND Isdelete!=1
UNION ALL
SELECT d.[CarriageLoadSiteId],
q.RootId RootId,
RootName RootName,
d.[Code],
d.Name,
d.ParentID,
d.[LoadSiteType],
d.[IsDelete],
d.CodeSAP,
d.DepartmentId,
d.Capacity,
d.MinLimit,
d.MaxLimit,
d.LoadSitePlaceTypeId
FROM CarriageLoadSite AS d WITH(NOLOCK)
INNER JOIN CarriageLoadSiteTreeView AS q ON d.ParentID = q.[CarriageLoadSiteId] WHERE d.IsDelete!=1
)
SELECT
ComplexId,
RootId Id,
cast(RootId as nvarchar(8))+'|Sclad'+IIF(RootId=max(R.CarriageLoadSiteId),'|finish','') [Uid],
RootName CarriageLoadSiteName,
ROUND(SUM(AMOUNT-movement-consumption)/1000,3) Amount,
cast(1 as bit) hasChildren,
T.FullPathId Path,
UparentId=IIF(#parent is null,'',#parent),
[Type]=0,
Petal = IIF(RootId=max(R.CarriageLoadSiteId),'|Sclad|finish','')
FROM (
SELECT
RootId
,RootName
,t.CarriageLoadSiteId
,t.MaterialId
,YEAR(t.Period) [Year]
,MONTH(t.Period) [Month]
,round( case when (t.Amount=0 or t.Amount is null) and (tt.Type=0 or [TypeAmountCarriage]=1 )then carr.[CertifNetto]else t.Amount end ,0 )[Amount]
,t.UnitId
, CarriageId
, tt.TurnoverTypeId
,round(dbo.GetMovementByTurnOverWithTempValue(t.turnoverid),5) movement
,dbo.GetConsumptionByTurnOver(t.turnoverid) consumption
,0 stockBegin
,round(t.Amount,0 ) CommingAmount
,case when (t.Amount=0 or t.Amount is null) and tt.Type=0 then 1 else 0 end [IsNotConfirmed]
,[TypeAmountCarriage]
,M.ComplexId
FROM Turnover t WITH(NOLOCK)
INNER JOIN TurnoverType tt ON tt.TurnoverTypeId = t.TurnoverTypeId
INNER JOIN CarriageLoadSiteTreeView l ON l.CarriageLoadSiteId = t.CarriageLoadSiteId
INNER JOIN [Carriages] carr on carr.[CarriagesID]=t.[CarriageId]
INNER JOIN Material M on M.MaterialID=t.MaterialId
WHERE YEAR(t.Period) = #Year AND
MONTH(t.Period) = #Month AND
l.LoadSiteType = 0 AND
tt.type in (0,5,4) AND
isclear=0 AND
M.MaterialSourceID in (select value from string_split(#materialSourceId, ','))
UNION ALL
SELECT RootId
,RootName
,s.CarriageLoadSiteId
,s.MaterialId
,#Year [Year]
,#Month [Month]
,round(s.Amount,0)
,s.UnitId
,CarriageId
,[TurnoverTypeId]
,round(dbo.GetMovementByStock(s.StockId),5) movement
,dbo.GetConsumptionByStock(s.StockId) consumption
,round(s.Amount,0)-s.spendStock
,0
,0 [IsNotConfirmed]
,[TypeAmountCarriage]
,M.ComplexId
FROM Stock s
INNER JOIN CarriageLoadSiteTreeView l ON l.CarriageLoadSiteId = s.CarriageLoadSiteId
INNER JOIN Material M on M.MaterialID=s.MaterialId
WHERE s.[Year] = #YearPrev AND
s.[Month] = #MonthPrev AND
s.[Type] = 0 AND
l.LoadSiteType = 0 AND
amount >0 AND
isclear=0 AND
M.MaterialSourceID in (select value from string_split(#materialSourceId, ','))
) as R
INNER JOIN CariageLoadSiteTree T on T.CarriageLoadSiteId=RootId
INNER JOIN string_split(#complexIds, ',') MM ON CAST(MM.value AS int) = R.ComplexId
WHERE AMOUNT-movement-consumption>10
GROUP BY RootName,RootId,ComplexId, T.FullPathId
ORDER BY RootName

Output parameter for stored procedure

I'm trying to write a value to an output parameter. In my THEN statement I'd like to either return outParam as 1 or 0 but not sure how to modify the below statement to do so. Can anyone help? Thanks!
CREATE PROCEDURE [dbo].[myProc]
#var1 UNIQUEIDENTIFIER,
#outParam BIT OUTPUT
AS
SELECT
CASE
WHEN EXISTS (SELECT 1
FROM [Table1] AS [i]
WHERE (CONVERT(VARCHAR(36), [i].[var1]) = #var1)
AND ([i].[BitColumn] = 1))
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT)
END
GO
You're ever so close! Just set it and go.
CREATE PROCEDURE [dbo].[myProc] #var1 uniqueidentifier,
#outParam bit OUTPUT
AS
SELECT #outParam = CASE
WHEN EXISTS (
SELECT 1
FROM [Table1] AS [i]
WHERE (CONVERT(VARCHAR(36), [i].[var1]) = #var1) AND ([i].[BitColumn] = 1))
THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT)
END;
GO

Simplify SQL where exists in clause

I want to simplify the below given procedure especially I want to remove most of the where clause filters such as IN and exists clauses.
For that, I have used a CTE and also declare a temp table and used it to get the select query that was talking long time since it was in where in clause. I would appreciate if you could show me some tricks in order to simplify this query.
ALTER PROCEDURE dbo.GetMappingBranchScenarios
#Mapping INT
#UserId INT= NULL
#BranchId INT = NULL
SELECT
BS.BranchId,
NULLIF( CC.Code, '' ) AS Code,
BS.BranchName,
BS.Active
FROM
Branch BS
LEFT OUTER JOIN
Code CC ON CC.BranchId = BS.BranchId
LEFT OUTER JOIN
BranchRule BRE ON BRE.MappingId = #Mapping
AND BRE.BranchId = BS.BranchId
WHERE
(BS.Active = 1
OR EXISTS (SELECT * FROM BranchRule BRE
WHERE BRE.BranchId = BS.BranchId
AND BRE.BranchId > 0
AND BRE.MappingId = #MappingId))
AND (#UserId IS NULL
OR BS.BranchId IN (SELECT BranchId
FROM branch2mapping.dbo.ListBranch(#UserId))
OR EXISTS (SELECT 1 FROM dbo.SecondaryMapping
WHERE Id = #UserId AND Admin = 1))
AND BS.BranchId = (CASE WHEN BranchId is NULL THEN BS.BranchID ELSE #BranchId END)
AND CC.Code = (CASE WHEN #Code IS NULL THEN CC.Code ELSE #Code END)
ORDER BY
CC.Code ASC
What I have done so far :
IF OBJECT_ID('tempdb..#Temp', 'U') IS NOT NULL
DROP TABLE #Temp
CREATE TABLE #Temp (BranchId INT)
SELECT BranchId
FROM branch2mapping.dbo.ListBranch(#UserId)
;WITH CTE AS
(
SELECT
BS.BranchId,
NULLIF(CC.Code, '' ) AS Code,
BS.BranchName, BS.Active
FROM
Branch BS
LEFT OUTER JOIN
Code CC ON CC.BranchId = BS.BranchId
LEFT OUTER JOIN
BranchRule BRE ON BRE.MappingId = #Mapping
AND BRE.BranchId = BS.BranchId
)
SELECT *
FROM CTE
WHERE
(CTE.Active = 1
OR EXISTS (SELECT * FROM BranchRule BRE
WHERE BRE.BranchId = CTE.BranchId
AND BRE.BranchId > 0
AND BRE.MappingId = #MappingId))
AND (#UserId IS NULL
OR BS.BranchId IN (SELECT * FROM #Temp)
OR EXISTS (SELECT 1 FROM dbo.SecondaryMapping
WHERE Id = #UserId AND Admin = 1)
)
AND BS.BranchId = (CASE WHEN BranchId is NULL THEN CTE.BranchID ELSE #BranchId END)
AND CTE.Code = (CASE WHEN #Code IS NULL THEN CTE.Code ELSE #Code END)
ORDER BY
CTE.Code ASC
Thank you for all your help.
Could you try if this is faster and still returning the same values with different filtering criteria?
ALTER PROCEDURE dbo.GetMappingBranchScenarios
#Mapping INT
#UserId INT= NULL
#BranchId INT = NULL
DECLARE #IsRuleExists BIT;
DECLARE #IsUrerADmin BIT;
IF EXISTS
(
SELECT 1
FROM Branch BS
INNER JOIN BranchRule BRE
ON BRE.BranchId = BS.BranchId
AND BRE.BranchId > 0
AND BRE.MappingId = #MappingId
)
BEGIN;
SET #IsRuleExists = 1;
END;
IF EXISTS
(
SELECT 1
FROM dbo.SecondaryMapping
WHERE Id = #UserId AND Admin = 1
) OR #UserId IS NULL
BEGIN;
SET #IsUrerADmin = 1;
END;
CREATE TABLE #Branches
(
[BranchId] INT
);
INSERT INTO #Branches ([BranchId])
SELECT BranchId
FROM branch2mapping.dbo.ListBranch(#UserId);
SELECT
BS.BranchId,
NULLIF( CC.Code, '' ) AS Code,
BS.BranchName,
BS.Active
FROM Branch BS
LEFT OUTER JOIN Code CC
ON CC.BranchId = BS.BranchId
WHERE
(
BS.Active = 1 OR #IsRuleExists = 1
)
AND
(
#IsUrerADmin = 1
OR
BS.BranchId IN (SELECT BranchId FROM #Branches)
)
AND BS.BranchId = (CASE WHEN BranchId is NULL THEN BS.BranchID ELSE #BranchId END)
AND CC.Code = (CASE WHEN #Code IS NULL THEN CC.Code ELSE #Code END)
ORDER BY CC.Code ASC;

SQL procedure AND OR statement

Im declaring two variables called Itemcode & Itemcode2.
Im trying to pull data that either contains Itemcode OR Itemcode2.
Something is wrong with my syntax, but I cannot see what. I've been awake for to long.....
Here is the problem line:
(AND d.ActivityCode = #ItemCode OR d.ActivityCode = #ItemCode2)
Here is the entire procedure:
USE [EnterpriseLive]
GO
/****** Object: StoredProcedure [dbo].[web_GetReviewTimesheetWIPDetailsByActivity4] Script Date: 12/03/2015 11:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[web_GetReviewTimesheetWIPDetailsByActivity4]
#Company char(15),
#ItemCode char(15),
#ItemCode2 char(15),
#StartYear smallint,
#EndYear smallint,
#ResourceCode char(15),
#ClientCode char(15),
#JobCode char(15),
#ActivityCode char(15)
AS
BEGIN
SELECT
w.LinkNumber,
w.SequenceNo,
w.TransactionDate AS TransactionDate,
w.JobCode AS JobCode,
j.JobName AS JobName,
c.ClientCode AS ClientCode,
c.ClientName AS ClientName,
w.ResourceCode AS ResourceCode,
r.ResourceName AS ResourceName,
d.ActivityCode AS ActivityCode,
(CASE d.PhaseNumber
WHEN 0 THEN d.JobDetailDescription
ELSE (SELECT JobDetailDescription
FROM JobDetail
WHERE Company = d.Company
AND JobCode = d.JobCode
AND PhaseNumber = d.PhaseNumber
AND JobDetailLevel = 1) + ': ' + d.JobDetailDescription
END) AS ActivityName,
w.JobSequenceNo AS JobSequenceNo,
NULL AS NCTimeCode,
(CASE w.Billable WHEN 1 then w.HoursWorked ELSE 0 END) AS BillableHours,
(CASE w.Billable WHEN 0 then w.HoursWorked ELSE 0 END) AS NonBillableHours,
w.HoursWorked AS TotalHours,
w.CostBase AS Cost,
(CASE w.Billable when 1 then w.CostBase + w.MarkupBase ELSE 0 END) AS Charge,
(CASE w.Billable when 0 then w.CostBase + w.MarkupBase ELSE 0 END) AS NonBillableClientCharge,
w.WIPNarrative AS WIPNarrative
FROM WIPDetails w
INNER JOIN JobHeader j ON w.Company = j.Company AND w.JobCode = j.JobCode
INNER JOIN Client c ON j.Company = c.Company AND c.ClientCode = j.JobClientCode
INNER JOIN JobDetail d ON w.Company = d.Company AND w.JobCode = d.JobCode AND w.JobSequenceNo = d.JobSequenceNo
INNER JOIN Resource r ON w.Company = r.Company AND r.ResourceCode = w.ResourceCode
WHERE w.Company = #Company
AND TransactionSource = 'TIME'
AND JobOverhead = '0'
(AND d.ActivityCode = #ItemCode OR d.ActivityCode = #ItemCode2)
AND w.TimesheetYear >= #StartYear and w.TimesheetYear <= #EndYear
AND r.ResourceCode IN (SELECT val FROM dbo.web_GetResourceCodeForWIPDetails(#Company, #ResourceCode))
AND c.ClientCode IN (SELECT val FROM dbo.web_GetClientCodeForWIPDetails(#Company, #ClientCode))
AND j.JobCode IN (SELECT val FROM dbo.web_GetJobCodeForWIPDetails(#Company, #JobCode))
ORDER BY w.TransactionDate, ResourceName, JobName, ActivityName
END
(AND d.ActivityCode = #ItemCode OR d.ActivityCode = #ItemCode2)
change to -
AND d.ActivityCode IN (#ItemCode, #ItemCode2)

Performance issue because of left join and multiple where clause

Here is the procedure
create PROCEDURE [dbo].[sample1] (
#param1 varchar(20) ,
#param2 VARCHAR(5),
#param3 varchar(max) = NULL,
#param4 varchar(max) = NULL,
#param5 varchar(max) = NULL,
#param6 bit = 1,
#param7 varchar(max) = NULL,
#param8 bit = 1,
#param9 varchar(max) = NULL,
#param10 varchar(max) = NULL,
#param11 varchar(max) = NULL,
#param12 varchar(5) = 'OP',
#param13 varchar(max) = NULL,
#TOP int = 101,
#SORTFIELD varchar(20) = 'DESCRIPTION',
#SORTDIRECTION varchar(5) = 'ASC'
)
AS
BEGIN
DECLARE
#NOW VARCHAR(10)=(SELECT CONVERT(varchar(10), GETDATE(), 112)),
#PHYSNAME VARCHAR(50)='',
#PHYPARAMS CHAR(1)='N'
/*********************************/
SELECT CPPACKAGE_PARAMS, MIN(CODE) AS MinCode, MAX(CODE) AS MaxCode
INTO #SNCPPKG_PARAMS_DTLS
FROM SNCPPKG_PARAMS_DTLS
WHERE CODETYPE = 5
GROUP BY CPPACKAGE_PARAMS
SELECT *
INTO #SNCPPACKAGERL
FROM SNCPPACKAGERL
WHERE DOMDEF = #param1
--SELECT *
--INTO #SNCPPROCDEF
--FROM SNCPPROCDEF
--WHERE DOMDEF = #param1
--SELECT *
--INTO #SNCPDIAGDEF
--FROM SNCPDIAGDEF
--WHERE DOMDEF = #param1
/*********************************/
SELECT
#PHYPARAMS=[ParamaterValue]
FROM [dbo].[sntbFacilityParamaters] with(nolock)
where [ParamaterTypeId] =
(SELECT TOP 1 [ParamaterTypeId]
FROM [dbo].[sntbParamaterTypeRef] with(nolock)
where ParamaterTypeName ='Physician Specific Packages')
and facid = #param2
IF( ISNULL(#PHYPARAMS ,'N')='N')
BEGIN
SET #param11=''
END
SET NOCOUNT ON;
CREATE TABLE #tempGLT1DET (CODEFROM VARCHAR(32))
INSERT INTO #tempGLT1DET
SELECT A.CODEFROM FROM snlocGLT1DET A with(nolock)
INNER JOIN snlocGLTABLE1 B with(nolock) ON A.GLTABLE1 = B.SYSKEY
WHERE A.CODETYPE IN ('4', '5')
AND NAME = 'AMA HCPCS'
AND (B.EFF_DATE <= #NOW OR B.EFF_DATE='')
AND (B.TRM_DATE >= #NOW OR B.TRM_DATE='')
AND (B.ACTIVATION_DT <= #NOW)
if(#top>300)
BEGIN
SET #top=300
END
IF(ISNULL(#param5,'')='' )
BEGIN
SET #param6=0
END
IF( ISNULL(#param7,'')='')
BEGIN
SET #param8=0
END
SELECT * INTO #TEMPPACKAGECOMPLETE
FROM
(SELECT --TOP(#TOP)
A.SYSKEY,
A.MCOMMORD,
A.SERVTYPE,
A.DESCRIPTION,
isnull(A.some_ver,'9') as some_ver,
A.ER,
A.OUTPATIENT,
A.INPATIENT,
A.DRG,
A.EFF_DATE,
A.TRM_DATE,
A.DOMDEF,
A.FINCLASS,
A.FORMORD,
A.AUDIT,
A.ALTDESC,
A.CODE,
B.TOTALCHARGE,
--null AS PHYSNAME,
A.PHYSNAME,
--NULL AS NPI,
A.NPI,
A.CPPACKAGE_PARAMS,A.PROCCODE,A.HCPCSRATES
--,row_number() over(partition BY A.SYSKEY
-- ORDER BY A.SYSKEY) rn
FROM
(SELECT *
FROM
(SELECT --TOP(#TOP)
CPPACKAGEDEF.SYSKEY,
isnull(CPPACKAGEDEF.some_ver,'9') as some_ver,
CPPACKAGEDEF.MCOMMORD,
CPPACKAGEDEF.SERVTYPE,
CPPACKAGEDEF.DESCRIPTION AS 'DESCRIPTION',
CPPACKAGEDEF.ER,
CPPACKAGEDEF.OUTPATIENT,
CPPACKAGEDEF.INPATIENT,
CPPACKAGEDEF.DRG,
CPPACKAGEDEF.EFF_DATE,
CPPACKAGEDEF.TRM_DATE,
CPPACKAGEDEF.DOMDEF,
CPPACKAGEDEF.FINCLASS,
CPPACKAGEDEF.FORMORD,
CPPACKAGEDEF.AUDIT,
CPPACKAGEDEF.ALTDESC,
REVDET.REVCODE, --REMOVE
P.PROCCODE,REVDET.HCPCSRATES,
CODE = CASE WHEN ISNULL(params.MinCode,'') = '' THEN ''
WHEN params.MinCode = params.MaxCode THEN params.MinCode
ELSE 'Multiple' END,
-- CODE = CASE WHEN
--(SELECT count(1)
-- FROM SNCPPKG_PARAMS_DTLS d with(nolock)
-- WHERE CPPACKAGE_PARAMS = CPPACKAGEDEF.CPPACKAGE_PARAMS
-- AND CODETYPE = 5) > 1 THEN 'Multiple' ELSE ISNULL(
-- (SELECT CODE
-- FROM SNCPPKG_PARAMS_DTLS d with(nolock)
-- WHERE CPPACKAGE_PARAMS = CPPACKAGEDEF.CPPACKAGE_PARAMS
-- AND CODETYPE = 5), '') END,
CPPACKAGEDEF.CPPACKAGE_PARAMS,
ISNULL(SC_TYPE,'R')AS SC_TYPE
FROM SNCPPACKAGEDEF AS CPPACKAGEDEF with(nolock)
LEFT JOIN #SNCPPKG_PARAMS_DTLS AS params ON params.CPPACKAGE_PARAMS = CPPACKAGEDEF.CPPACKAGE_PARAMS
LEFT JOIN #SNCPPACKAGERL REVDET ON REVDET.CPPACKAGEDEF= CPPACKAGEDEF.syskey-- and REVDET.domdef= #param1
--start:rajesh:for diag and proc
left join SNCPPROCDEF p with (nolock) on (P.CPPACKAGEDEF = CPPACKAGEDEF.syskey) and p.domdef= #param1
left join SNCPDIAGDEF d with (nolock) on (d.CPPACKAGEDEF = CPPACKAGEDEF.syskey) and d.domdef= #param1
--LEFT JOIN SNCPPACKAGERL pkgRL ON pkgRL.CPPACKAGEDEF= C.syskey
where
(
((isnull(#param5,'')='') or (d.DIAGCODE like #param5+'%'))
and
((isnull(#param7,'')='') or (p.PROCCODE like #param7+'%'))
)
AND
(
((#param13='9') AND (ISNULL(CPPACKAGEDEF.some_ver,'9')='9')) OR
((#param13='0') AND (ISNULL(CPPACKAGEDEF.some_ver,'9')='0'))
OR
(ISNULL(#param13,'')='')
)
--AND REVDET.
-- AND p.DOMDEF = #param1
--AND d.DOMDEF = #param1
AND
(
ISNULL(#param7,'')=''
OR
(
(#param12='IP' AND ISNULL(#param7,'')<>'')
--AND
--(
--( P.PROCCODE IN
-- ( SELECT DISTINCT DESTCODE FROM snVwCodeXWalk XWALK WHERE XWALK.SOURCECODE = #param10)
--)
--)
)
OR
(
((#param12='OP' OR #param12='ER') AND ISNULL(#param7,'')<>'')
AND
(
REVDET.HCPCSRATES like #param10+'%'
)
)
)
AND
(
(
( (#param5=1 AND #param8=0 )
AND
(d.SEQUENCE=1)
)
--or ISNULL(#param5,'')=''
)
OR
(
((#param8=1 AND #param6=0) AND
(p.SEQUENCE=1) )
--OR ISNULL(#param7,'')=''
)
OR
(
(
(#param5=1 )--AND ISNULL(#param5,'')<>'')
AND (#param8=1)-- AND ISNULL(#param7,'')<>'')
AND (p.SEQUENCE=1 )
AND (d.SEQUENCE=1 )
)
)
OR
(#param5=0 AND #param8=0)
)
--end:rajesh for diag and proc
--where SYSKEY = '126FAQ00249R' and
AND
(
(CPPACKAGEDEF.DESCRIPTION LIKE '%'+#param3+'%')
OR (CPPACKAGEDEF.ALTDESC LIKE '%'+#param3+'%')
OR (ISNULL(#param3,'')='')
)
AND
( (REVDET.REVCODE LIKE #param9+'%') OR (ISNULL(#param9,'')='' ))
AND( (CPPACKAGEDEF.DRG LIKE #param4+'%') OR (ISNULL(#param4,'')='') )
AND
-- ISNULL(CPPACKAGEDEF.SC_TYPE,'R')=
-- CASE WHEN #PHYPARAMS='Y'
-- THEN 'P'
--ELSE
--'R'
--end
(
(#PHYPARAMS='Y' AND CPPACKAGEDEF.SC_TYPE='P' AND ISNULL(#param11,'')<>'' )
OR
(#PHYPARAMS='Y'AND ISNULL(#param11,'')='' )
OR
(#PHYPARAMS='N'AND ISNULL(CPPACKAGEDEF.SC_TYPE,'R')='R' )
)
AND (CPPACKAGEDEF.EFF_DATE <= #NOW OR ISNULL(CPPACKAGEDEF.EFF_DATE,'')='')
AND (CPPACKAGEDEF.TRM_DATE >= #NOW OR ISNULL(CPPACKAGEDEF.TRM_DATE,'')='')
AND CPPACKAGEDEF.DOMDEF=#param1
--AND p.DOMDEF=#param1
--AND d.DOMDEF=#param1
) CPPACKAGEDEF
LEFT JOIN
(SELECT PHYSNAME,
phyPARAMS,
NPI
FROM
(SELECT DISTINCT b.PHYSNAME,
b.NPI,
cp.SYSKEY phyPARAMS,
ROW_NUMBER() OVER (PARTITION BY b.NPI,cp.SYSKEY
ORDER BY b.MDATE DESC) AS rowNum
FROM dbo.BILLPHYS b
INNER JOIN SNCPPACKAGE_PARAMS cp with(nolock) ON cp.NPI = b.NPI
WHERE ISNULL(b.NPI, '') <> '') phy
WHERE phy.rowNum=1) B ON B.phyPARAMS = CPPACKAGEDEF.CPPACKAGE_PARAMS
WHERE (CPPACKAGEDEF.SYSKEY <> ''
AND CPPACKAGEDEF.AUDIT = 'Z')
AND (CPPACKAGEDEF.DOMDEF IN (#param1))
AND (
((CPPACKAGEDEF.INPATIENT = 'Y') AND (#param12='IP'))
OR
((CPPACKAGEDEF.OUTPATIENT = 'Y') AND (ISNULL(#param12,'OP')='OP'))
OR
((#param12='ER' AND CPPACKAGEDEF.OUTPATIENT = 'Y' )AND CONVERT(INT,CPPACKAGEDEF.REVCODE) BETWEEN 450 AND 459)
)
) A
LEFT JOIN
(SELECT SUM(CONVERT(MONEY, LINECHARGE) * UNITS) AS 'TOTALCHARGE', CPPACKAGEDEF FROM
(SELECT LINECHARGE,
UNITS,
CPPACKAGEDEF
FROM #SNCPPACKAGERL with(nolock)) B
GROUP BY CPPACKAGEDEF) B ON A.SYSKEY = B.CPPACKAGEDEF
) A
-- LEFT JOIN SNCPPACKAGERL REVDET ON REVDET.CPPACKAGEDEF= A.syskey AND REVDET.DOMDEF=#param1
WHERE
--rn= 1
--AND
( (A.PHYSNAME LIKE #param11+'%') OR (ISNULL(#param11,'')='' ))
--
--select * from #TEMPPACKAGECOMPLETE
---
--SELECT count(DISTINCT SYSKEY)FROM #TEMPPACKAGE
-- gpant start
Select top (#top) * into #TEMPPACKAGE from (Select *,row_number() over(partition BY SYSKEY
ORDER BY SYSKEY) rn from #TEMPPACKAGECOMPLETE where ((
ISNULL(#param7,'')=''
OR
(
(#param12='IP' AND ISNULL(#param7,'')<>'')
AND
(
( PROCCODE IN
( SELECT DISTINCT DESTCODE FROM snVwCodeXWalk XWALK WHERE XWALK.SOURCECODE = #param10)
)
)
)
OR
(
((#param12='OP' OR #param12='ER') AND ISNULL(#param7,'')<>'')
--AND
--(
-- HCPCSRATES like #param10+'%'
--)
)
) ))t where rn =1
-- --gpant end
SELECT
--count(distinct T.SYSKEY) AS ScSyskey
T.SYSKEY AS ScSyskey,
T.DESCRIPTION AS ScDescription,
T.PHYSNAME AS ScPhysician ,
CASE WHEN ISNULL(#param12 ,'OP')='OP' THEN 'OP'
ELSE
CASE WHEN #param12='IP' THEN 'IP'
ELSE
CASE WHEN #param12='ER' THEN 'ER'
END
END
END ScPatientType,
--'I' AS ScPatientType,
T.DRG AS ScDiagnosis,
T.CODE AS ScPrimaryCdmProcedure ,
CASE WHEN P.DIAG_PRIMARYCODE='Y' THEN P.DIAGCODE ELSE NULL END AS ScPrimaryIcdDiagnosis,
CASE WHEN P.PROC_PRIMARYCODE='Y' THEN P.PROCCODE ELSE NULL END AS ScPrimaryIcdProcedure,
ISNULL(T.TOTALCHARGE, 0) AS ScAmount,
T.MCOMMORD AS ScClaimCount,
C.CODE AS ScCode,
C.CODETYPEDESC AS ScCodeType,
T.DESCRIPTION AS ScCodeDescription,
CAST(C.DATEFROM AS DATETIME) AS ScDateFrom,
CAST(C.DATETO AS DATETIME) As ScDateTo,
REVCODE.UNITS AS CdmUnits,
REVCODE.UNITSORDAYS AS CdmUnitType,
REVCODE.CPT4 AS CdmCode,
REVCODE.MODIFIERS AS CdmModifier,
REVCODE.REVCODE AS CdmRevenueCode,
REVCODE.REVDESC AS CdmDescription,
REVCODE.CHARGECODE AS CdmChargeCode,
REVCODE.LINECHARGE AS CdmPerUnitCharge,
P.DIAGCODE AS IcdDiagCode,
P.DIAG_PRIMARYCODE AS IcdDiagIsPrimary,
P.DIAGDESC AS IcdDiagDescription,
P.PROCCODE AS IcdProcCode,
P.PROC_PRIMARYCODE AS IcdProcIsPrimary,
P.PROCDESCS AS IcdProcDescription,
p.ProcedureSequence,
p.DiagSequence
FROM #TEMPPACKAGE T
LEFT JOIN
(
select distinct x.syskey as CPPACKAGEDEF,
proce.PROCCODE AS PROCCODE,
diag.DIAGCODE AS DIAGCODE,
PROCDESC.PROCDESC AS PROCDESCS ,
DIAGDESC.DIAGDESC AS DIAGDESC,
ISNULL(PROCDESC.ICD_CODE_VERSION,'ICD9Proc') as proccode_version ,
ISNULL(DIAGDESC.ICD_CODE_VERSION,'ICD9Dx') as diagcode_version, --ISNULL(p.DIAGDESC.ICD_CODE_VERSION,'ICD9Dx')
PROCDESC.VALID AS ISPROCVALID,
DIAGDESC.VALID AS ISDIAGVALID,
CASE WHEN PROCE.SEQUENCE =1 THEN 'Y' ELSE 'N' END AS PROC_PRIMARYCODE,
CASE WHEN DIAG.SEQUENCE =1 THEN 'Y' ELSE 'N' END AS DIAG_PRIMARYCODE ,
PROCE.SEQUENCE AS ProcedureSequence,
DIAG.SEQUENCE AS DiagSequence
from
--(
(
select distinct c.syskey as syskey
from snCPPACKAGEDEF C where domdef=#param1
)x
left join SNCPPROCDEF proce on (x.syskey=proce.CPPACKAGEDEF and proce.DOMDEF = #param1)
left join SNCPDIAGDEF diag on (x.syskey=diag.CPPACKAGEDEF and diag.DOMDEF = #param1)
left join SNLOCCP_DTPROC PROCDESC with(nolock) ON (proce.PROCCODE = PROCDESC.PROCCODE and PROCDESC.valid='Y' )
LEFT JOIN SNLOCCP_DTDIAG DIAGDESC with(nolock) ON (diag.DIAGCODE = DIAGDESC.DIAGCODE and DIAGDESC.valid='Y')
) P
ON T.SYSKEY = P.CPPACKAGEDEF
LEFT JOIN
VWCODEDESC AS C ON T.CPPACKAGE_PARAMS = C.CPPACKAGE_PARAMS
LEFT JOIN
(SELECT DISTINCT pkgRL.CPPACKAGEDEF, pkgRL.CHARGECODE, pkgRL.UNITS, pkgRL.UNITSORDAYS, pkgRL.SEQUENCE,
pkgRL.PERRELEVANCE, CAST(ISNULL(pkgRL.MOD1,'') + ','+ ISNULL(pkgRL.MOD2,'') + ','+ ISNULL(pkgRL.MOD3,'')+ ','+ ISNULL(pkgRL.MOD4,'') AS VARCHAR(50)) AS MODIFIERS, pkgRL.UNITWEIGHT,
ISNULL(pkgRL.REVDESC,'Procedure no longer exists!') AS REVDESC, pkgRL.HCPCSRATES,
pkgRL.REVCODE, pkgRL.LINECHARGE, pkgRL.STATCHARGE, pkgRL.CDMCHARGE,
CASE WHEN pkgRL.HCPCSRATES = '' OR pkgRL.HCPCSRATES IN (SELECT CODEFROM FROM #tempGLT1DET) THEN pkgRL.HCPCSRATES ELSE 'Invalid HCPCS Code:' + pkgRL.HCPCSRATES END AS 'CPT4'
FROM #SNCPPACKAGERL pkgRL ) revcode
ON T.SYSKEY = revcode.CPPACKAGEDEF
where
--(ISNULL(p.PROCCODE,'')<>'' OR ISNULL(p.DIAGCODE,'')<>'')
--AND
ISNULL(ISDIAGVALID,'Y')='Y' AND ISNULL(ISPROCVALID,'Y')='Y'
and
(
(
(
(T.some_ver='9' AND ISNULL(p.diagcode_version,'ICD9Dx')='ICD9Dx' )
OR
(T.some_ver='0' AND p.diagcode_version='ICD10CM')
OR
(ISNULL(P.DIAGCODE,'')='')
)
AND
(
(T.some_ver='9' AND ISNULL(p.proccode_version,'ICD9Proc')='ICD9Proc' )
OR
(T.some_ver='0' AND p.proccode_version='ICD10PCS')
OR
(ISNULL(P.PROCCODE,'')='')
)
)
OR
((ISNULL(P.DIAGCODE,'')='')OR(ISNULL(P.PROCCODE,'')='') )
)
ORDER BY CASE
WHEN UPPER(#SORTFIELD) = 'DESCRIPTION' AND
#SORTDIRECTION = 'DESC' THEN T.DESCRIPTION
END DESC,
CASE
WHEN UPPER(#SORTFIELD) = 'DESCRIPTION' AND
#SORTDIRECTION != 'DESC' THEN T.DESCRIPTION
END ASC,
CASE
WHEN UPPER(#SORTFIELD) = 'CHARGECODE' AND
#SORTDIRECTION = 'DESC' THEN
T.SYSKEY
END DESC,
CASE
WHEN UPPER(#SORTFIELD) = 'CHARGECODE' AND
#SORTDIRECTION != 'DESC' THEN
T.SYSKEY
END ASC
END
In the procedure param1 and param2 are mandatory. when I search with the rest of the params, my procedure is giving me average performance(withing 10-12 seconds). But When I search with param10 I am getting the result in 16 minutes which is unacceptable. I have tried to tweak the procedure by changing the where clause positions, implementing temp tables but did not help.
Suggest some ways which can increase the performance with only param10.
Try creating an index on REVDET.HCPCSRATES and then on snVwCodeXWalk.SOURCECODE. Try one first, then the other, then both, and see what effect it has.

Resources