0% found this document useful (0 votes)
54 views

Problematic SQL

This document contains an SQL stored procedure that performs a query on a dco_account table to retrieve account information. It uses common table expressions to first select account records owned by or associated with the user or business unit, and also accounts the user has access to based on an object permissions table. It then unions these results and selects the top 12 records ordered by name and ID where the state is a particular value.

Uploaded by

CSK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Problematic SQL

This document contains an SQL stored procedure that performs a query on a dco_account table to retrieve account information. It uses common table expressions to first select account records owned by or associated with the user or business unit, and also accounts the user has access to based on an object permissions table. It then unions these results and selects the top 12 records ordered by name and ID where the state is a particular value.

Uploaded by

CSK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

exec sp_executesql N'WITH "dco_account0Security" as (

select dco_name as "dco_name", dco_Value as "dco_Value", dco_AccountType as


"dco_AccountType", dco_Description as "dco_Description", dco_Trailing12Revenue as
"dco_Trailing12Revenue", dco_RecordId as "dco_RecordId", OwnerId as "OwnerId",
dco_NetCashEquivalent as "dco_NetCashEquivalent", dco_Manager as "dco_Manager",
dco_PrimaryContact as "dco_PrimaryContact", dco_accountId as "dco_accountId",
VersionNumber as "VersionNumber", TransactionCurrencyId as "TransactionCurrencyId",
dco_RecordIdName as "dco_RecordIdName", dco_RecordIdYomiName as
"dco_RecordIdYomiName", OwnerIdType as "OwnerIdType", OwnerIdName as "OwnerIdName",
OwnerIdYomiName as "OwnerIdYomiName", dco_PrimaryContactName as
"dco_PrimaryContactName", dco_PrimaryContactYomiName as
"dco_PrimaryContactYomiName", TransactionCurrencyIdName as
"TransactionCurrencyIdName", statecode as "statecode", OwningBusinessUnit as
"OwningBusinessUnit" from [dco_account] as "dco_account0" where
("dco_account0".OwnerId in
(@userPrincipalWithBasicDepth00,@userPrincipalWithBasicDepth10,@userPrincipalWithBa
sicDepth20)
or "dco_account0".OwningBusinessUnit in (@buId00)
)
UNION
select dco_name as "dco_name", dco_Value as "dco_Value", dco_AccountType as
"dco_AccountType", dco_Description as "dco_Description", dco_Trailing12Revenue as
"dco_Trailing12Revenue", dco_RecordId as "dco_RecordId", OwnerId as "OwnerId",
dco_NetCashEquivalent as "dco_NetCashEquivalent", dco_Manager as "dco_Manager",
dco_PrimaryContact as "dco_PrimaryContact", dco_accountId as "dco_accountId",
VersionNumber as "VersionNumber", TransactionCurrencyId as "TransactionCurrencyId",
dco_RecordIdName as "dco_RecordIdName", dco_RecordIdYomiName as
"dco_RecordIdYomiName", OwnerIdType as "OwnerIdType", OwnerIdName as "OwnerIdName",
OwnerIdYomiName as "OwnerIdYomiName", dco_PrimaryContactName as
"dco_PrimaryContactName", dco_PrimaryContactYomiName as
"dco_PrimaryContactYomiName", TransactionCurrencyIdName as
"TransactionCurrencyIdName", statecode as "statecode", OwningBusinessUnit as
"OwningBusinessUnit" from [dco_account] as "dco_account0" where
("dco_account0".dco_accountId in (select ObjectId from
fn_POARetrieveMultipleNonHierarchy(@SystemUserId0, @ObjectTypeCode0)))
)
select
top 12 "dco_account0".dco_name as "dco_name"
, "dco_account0".dco_Value as "dco_value"
, "dco_account0".dco_AccountType as "dco_accounttype"
, "dco_account0".dco_Description as "dco_description"
, "dco_account0".dco_Trailing12Revenue as "dco_trailing12revenue"
, "dco_account0".dco_RecordId as "dco_recordid"
, "dco_account0".OwnerId as "ownerid"
, "dco_account0".dco_NetCashEquivalent as "dco_netcashequivalent"
, "dco_account0".dco_Manager as "dco_manager"
, "dco_account0".dco_PrimaryContact as "dco_primarycontact"
, "dco_account0".dco_accountId as "dco_accountid"
, convert(bigint, "dco_account0".VersionNumber) as "versionnumber"
, "dco_account0".TransactionCurrencyId as "transactioncurrencyid"
, "dco_account0".dco_RecordIdName as "dco_recordidname"
, "dco_account0".dco_RecordIdYomiName as "dco_recordidyominame"
, "dco_account0".OwnerIdType as "owneridtype"
, "dco_account0".OwnerIdName as "owneridname"
, "dco_account0".OwnerIdYomiName as "owneridyominame"
, "dco_account0".dco_PrimaryContactName as "dco_primarycontactname"
, "dco_account0".dco_PrimaryContactYomiName as "dco_primarycontactyominame"
, "dco_account0".TransactionCurrencyIdName as "transactioncurrencyidname"
from
dco_account0Security as "dco_account0"
where
("dco_account0".statecode = @statecode0)
order by
"dco_account0".dco_name asc
, "dco_account0".dco_accountId asc',N'@statecode0
int,@userPrincipalWithBasicDepth00 uniqueidentifier,@userPrincipalWithBasicDepth10
uniqueidentifier,@userPrincipalWithBasicDepth20 uniqueidentifier,@buId00
uniqueidentifier,@SystemUserId0 uniqueidentifier,@ObjectTypeCode0
int',@statecode0=0,@userPrincipalWithBasicDepth00='60AA64C7-54B1-E811-80F5-
005056B52F38',@userPrincipalWithBasicDepth10='B7864236-AD48-E811-99D2-
0050569BD2AB',@userPrincipalWithBasicDepth20='AE43C5F5-5DB9-E011-8DF9-
1CC1DEE8AA5F',@buId00='36D93EF2-7275-E111-8A70-
005056AE0065',@SystemUserId0='0CBA8520-B886-E711-80F3-
005056959154',@ObjectTypeCode0=10006

You might also like