|
CHill60 wrote: You might get a better response with some sample data and expected results This is getting old now. When posting SQL queries and asking "what is wrong" or "how does this not work" or ... well, anything, you should include some sample data for all of the tables used in your query.
Nobody wants to use up their spare time (which is how this forum works) traipsing through 200+ lines of code in the off-chance they might spot something that could be improved.
Help us to help you.
|
|
|
|
|
Some of the tables in that Query have 15 Columns too, I don't know how can I put all that Data here on the forum itself, it will be more huge message than currently, I am assuming this current message itself is too big.
What I am asking is, are there any places that I can be suspicious of taking more time than normal. Any help would be very very helpful buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
indian143 wrote: What I am asking is, are there any places that I can be suspicious of taking more time than normal. The usual things.
Converting varchars to dates is a big timewaster, having magical numbers shows a design-flaw, and every function that is called on each value will slow the thing down fast.
8 Ways to Fine-tune your SQL Queries (for production databases) | Sisense[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi all. I was in a meeting recently where the chair was extolling the virtues of Graph databases. So much so that he asserted, if they’d been invented, Ralph Kimball would never have become involved with dimensional modelling and would have used graph databases instead. I have been involved with dimensional modelling (and cubes) for many years, but can’t claim to have built a Graph database. However, I understand their strength is in identifying relationships. If you’re working with data that is hierarchical in nature and, the relationships are evident, then Graph is not appropriate. Would be interested in you views. Cheers
|
|
|
|
|
DADom wrote: So much so that he asserted, if they’d been invented, Ralph Kimball would never have become involved with dimensional modelling and would have used graph databases instead. Keep any evangelists away from these discussions. You don't need a salesman on your team.
DADom wrote: Would be interested in you views. My strength is identifying relationships too, so I prefer to store relational data in a RDBMS in a structure that is at least in BCNF. It is a proven way which guarantees consistency and correctness.
According to the wiki, a graph db excells where data is "difficult to model" (and I agree with the comment "according to whom"). So, to evaluate it, you come looking for anecdotes.
I suggest you make a list (and check it twice) with advantages and disadvantages of both, and decide which are more important to you. THAT is the correct way out of these discussions - you will need to justify your choice, which is not done by pointing to an anecdote on codeproject, but by showing which of the two choices is the better fit in your specific case.
Personally, I'd say that the choice is obvious; Most RDBMSs are stable and well-optimized for data storage and retrieval, and there are a lot of resources on SQL92 (talk about backward compatibility eh?) Graph-databases would require something else than SQL probably, adding to the costs (and riscs).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: According to the wiki,
Where is the wiki? Regards.
|
|
|
|
|
John 13564154 wrote:
Where is the wiki? Regards. We don't have one; I was referring to this[^] wikipedia article.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have a table product, columns:id,date,product,productname
I want to create a insert trigger, when I insert id,date,product, the productname will auto update in to the table(the product=productname... I don't know how to make the equation, please help me.
sorry for my terrible English.
modified 22-May-18 5:39am.
|
|
|
|
|
Why have two columns with the same data?
Have you tried anything at all yet?
|
|
|
|
|
CREATE TRIGGER (Transact-SQL) | Microsoft Docs[^]
CREATE TRIGGER YourTriggerName
ON YourTableName
AFTER insert, update
As
BEGIN
SET NOCOUNT ON;
If UPDATE(FK)
BEGIN
UPDATE
T
SET
RedundantDuplicateColumn = T2.Name
FROM
YourTable As T
INNER JOIN inserted As I
ON I.PK = T.PK
LEFT JOIN YourOtherTable As T2
ON T2.PK = T.FK
;
END;
END
Replace the dummy table and column names with the real table and column names.
Remember that triggers will fire once per batch, not once per row. There could be multiple rows in the inserted table.
But as CHill60 said, duplicating the product name in both tables seems like a bad design. If you have the ID of the product, you can simply join to the product table to get the name on demand.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is a REALLY BAD design, instead of having a separate table for productname create a view
create view vwProductName
as
select distinct product as productname from product
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Am I missing something ... where's the table for the ProductName mentioned?
|
|
|
|
|
OP wrote:
the productname will auto update in to the table(the product=productname.
So yes I think you missed this.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It's an ERP bill, customer want to input the batch number, but they don't want to use any rules, just want to fetch the bill number into that field.
|
|
|
|
|
The comments still stand - there should be no reason to store the productname in a different table especially as it is user input and free form.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have a query that is using FOR XML PATH, when the child elements has values then its giving the Child elements, but when there are no values coming out of query for the Child elements, its finishing the X-path by putting and end tag (\), but I want the all the elements to be created if there are values are not, it doesn't have to repeat the elements as if there are values but at least one occurrence has to be there even if there are values or don't have values.
Below are the example for it.
Case 1 is the file that it is creating with all the values and elements, there are elements that are repeated I am not putting all that xml here to reduce the size, but I want to create all the elements of the xml even if there are values or no values at least one occurrence.
<TB_BILLING_PROVIDER_FILES>
<TB_TRADING_PARTNER>
<Owner>DMH</Owner>
<TP_EIN>9xxxxxxx1</TP_EIN>
<TP_NAME>Alameda</TP_NAME>
<County_Code>01</County_Code>
<TB_BILLING_PROVIDER_FILE>
<TB_SERVICE_FACILITY>
<Service_Facility_NPI>xxxxxxxx7</Service_Facility_NPI>
<County_Owned_Indicator>true</County_Owned_Indicator>
<Service xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Procedure_Code>Hxxxxx</Procedure_Code>
<Modifier1>HE</Modifier1>
<Modifier2>TG</Modifier2>
<Modifier3/>
<Modifier4/>
<From_Date>19811201</From_Date>
<To_Date>20030623</To_Date>
<Revenue_Code/>
<Place_Of_Service/>
<Taxonomy_Code/>
</Service>
</TB_SERVICE_FACILITY>
</TB_BILLING_PROVIDER_FILE>
</TB_TRADING_PARTNER>
</TB_BILLING_PROVIDER_FILES>
The Case 2 xml is as below:
<TB_BILLING_PROVIDER_FILES>
<TB_TRADING_PARTNER>
<Owner>DMH</Owner>
<TP_EIN>xxxxxxxxx</TP_EIN>
<TP_NAME>Alameda</TP_NAME>
<County_Code>01</County_Code>
<TB_BILLING_PROVIDER_FILE/>
</TB_TRADING_PARTNER>
</TB_BILLING_PROVIDER_FILES>
The sql script for the case 1 is:
SELECT
vw_OwnerXML5010.Owner,
vw_OwnerXML5010.Billing_EIN AS TP_EIN,
vw_OwnerXML5010.TP_Name AS TP_NAME,
vw_OwnerXML5010.County_Code AS County_Code,
(
SELECT
(
SELECT
vw_ServiceFacilityXML5010.Service_Facility_NPI AS "Service_Facility_NPI",
vw_ServiceFacilityXML5010.County_Owned_Indicator AS "County_Owned_Indicator",
(
Select
vw_ServicesXML5010.Procedure_Code AS "Procedure_Code",
vw_ServicesXML5010.Modifier1 As "Modifier1",
vw_ServicesXML5010.Modifier2 AS "Modifier2",
vw_ServicesXML5010.Modifier3 AS "Modifier3",
vw_ServicesXML5010.Modifier4 AS "Modifier4",
vw_ServicesXML5010.From_Date AS "From_Date",
vw_ServicesXML5010.To_Date AS "To_Date",
vw_ServicesXML5010.Revenue_Code AS "Revenue_Code",
vw_ServicesXML5010.Place_Of_Service AS "Place_Of_Service",
vw_ServicesXML5010.Taxonomy_Code AS "Taxonomy_Code"
FROM
vw_ServicesXML5010
WHERE
vw_ServiceFacilityXML5010.Service_Facility_NPI = vw_ServicesXML5010.Service_Facility_NPI
and vw_ServiceFacilityXML5010.County_Code = vw_ServicesXML5010.County_Code
and vw_ServiceFacilityXML5010.Billing_EIN = vw_ServicesXML5010.Billing_EIN
-- and vw_ServiceFacilityXML5010.County_Code in ('01', '02')
-- and vw_ServiceFacilityXML5010.Service_Facility_NPI = '1932328580'
FOR XML PATH('Service'), TYPE , ELEMENTS XSINIL
)
FROM
vw_ServiceFacilityXML5010
WHERE
vw_ServiceFacilityXML5010.County_Code = vw_OwnerXML5010.County_Code
and vw_ServiceFacilityXML5010.Billing_EIN = vw_OwnerXML5010.Billing_EIN
-- and vw_ServiceFacilityXML5010.County_Code in ( '01', '02')
-- and vw_ServicesXML5010.Service_Facility_NPI = '1932328580'
FOR XML PATH ('TB_SERVICE_FACILITY'), TYPE
-- ) AS "BILLING_PROVIDERS/TB_BILLING_PROVIDER_FILE/TB_SERVICE_FACILITY"
--) AS "TB_BILLING_PROVIDER_FILE/TB_SERVICE_FACILITY"
--) AS "TB_BILLING_PROVIDER_FILE"
) FOR XML PATH ('TB_BILLING_PROVIDER_FILE'), TYPE
)
FROM
vw_OwnerXML5010
-- where vw_OwnerXML5010.County_Code in ('01', '02')
ORDER BY vw_OwnerXML5010.County_Code
FOR XML PATH ('TB_TRADING_PARTNER'), root('TB_BILLING_PROVIDER_FILES')
The sql script for the case 2 is:
SELECT
vw_OwnerXML5010.Owner,
vw_OwnerXML5010.Billing_EIN AS TP_EIN,
vw_OwnerXML5010.TP_Name AS TP_NAME,
vw_OwnerXML5010.County_Code AS County_Code,
(
SELECT
(
SELECT
vw_ServiceFacilityXML5010.Service_Facility_NPI AS "Service_Facility_NPI",
vw_ServiceFacilityXML5010.County_Owned_Indicator AS "County_Owned_Indicator",
(
Select
vw_ServicesXML5010.Procedure_Code AS "Procedure_Code",
vw_ServicesXML5010.Modifier1 As "Modifier1",
vw_ServicesXML5010.Modifier2 AS "Modifier2",
vw_ServicesXML5010.Modifier3 AS "Modifier3",
vw_ServicesXML5010.Modifier4 AS "Modifier4",
vw_ServicesXML5010.From_Date AS "From_Date",
vw_ServicesXML5010.To_Date AS "To_Date",
vw_ServicesXML5010.Revenue_Code AS "Revenue_Code",
vw_ServicesXML5010.Place_Of_Service AS "Place_Of_Service",
vw_ServicesXML5010.Taxonomy_Code AS "Taxonomy_Code"
FROM
vw_ServicesXML5010
WHERE
vw_ServiceFacilityXML5010.Service_Facility_NPI = vw_ServicesXML5010.Service_Facility_NPI
and vw_ServiceFacilityXML5010.County_Code = vw_ServicesXML5010.County_Code
and vw_ServiceFacilityXML5010.Billing_EIN = vw_ServicesXML5010.Billing_EIN
-- and vw_ServiceFacilityXML5010.County_Code in ('01', '02')
-- and vw_ServiceFacilityXML5010.Service_Facility_NPI = '1932328580'
FOR XML PATH('Service'), TYPE , ELEMENTS XSINIL
)
FROM
vw_ServiceFacilityXML5010
WHERE
vw_ServiceFacilityXML5010.County_Code = vw_OwnerXML5010.County_Code
and vw_ServiceFacilityXML5010.Billing_EIN = vw_OwnerXML5010.Billing_EIN
-- and vw_ServiceFacilityXML5010.County_Code in ( '01', '02')
-- and vw_ServicesXML5010.Service_Facility_NPI = '1932328580'
FOR XML PATH ('TB_SERVICE_FACILITY'), TYPE
-- ) AS "BILLING_PROVIDERS/TB_BILLING_PROVIDER_FILE/TB_SERVICE_FACILITY"
--) AS "TB_BILLING_PROVIDER_FILE/TB_SERVICE_FACILITY"
--) AS "TB_BILLING_PROVIDER_FILE"
) FOR XML PATH ('TB_BILLING_PROVIDER_FILE'), TYPE
)
FROM
dbo.vw_SDMCPhaseTwoParentLevelXML vw_OwnerXML5010
-- where vw_OwnerXML5010.County_Code in ('01', '02')
ORDER BY vw_OwnerXML5010.County_Code
FOR XML PATH ('TB_TRADING_PARTNER'), root('TB_BILLING_PROVIDER_FILES')
I am not understanding how are these two different, I just want to create the complete xml at least with one occurrence of all the elements, can anybody please help me, any help a suggestion a link or code snippet, anything helps. Thanks in advance buddies.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Last tuesday I made a suggestion to you that would probably help you get assistance.
CHill60 wrote: You might get a better response with some sample data and expected results You've given us the outputs but still haven't provided any sample data ... on the tables (or views) vw_ServicesXML5010 , vq_ServiceFacilityXML5010 , vw_OwnerXML5010 or dbo.vw_SDMCPhaseTwoParentLevelXML
You have said that you don't understand how the two scripts are different, yet one of them is reading from vw_OwnerXML5010 but the other is reading from dbo.vw_SDMCPhaseTwoParentLevelXML having been given an alias of vw_OwnerXML5010. I suggest you start by comparing the output of the following sql commands
SELECT * FROM vb_OwnerXML5010 and
SELECT * FROM dbo.vw_SDMCPhaseTwoParentLevelXML introducing an appropriate WHERE clause to both.
We can't help you any further without sample data.
|
|
|
|
|
Hi,
What is the equivalent of the following query without the FOR XML PATH, when removed the FOR XML PATH from the query it is giving error, can anybody please help with this regards, thanks in advance buddies.
SELECT
vw_OwnerXML5010.Owner,
vw_OwnerXML5010.Billing_EIN AS TP_EIN,
vw_OwnerXML5010.TP_Name AS TP_NAME,
vw_OwnerXML5010.County_Code AS County_Code,
(
SELECT
(
SELECT
vw_ServiceFacilityXML5010.Service_Facility_NPI AS "Service_Facility_NPI",
vw_ServiceFacilityXML5010.County_Owned_Indicator AS "County_Owned_Indicator",
(
Select
vw_ServicesXML5010.Procedure_Code AS "Procedure_Code",
vw_ServicesXML5010.Modifier1 As "Modifier1",
vw_ServicesXML5010.Modifier2 AS "Modifier2",
vw_ServicesXML5010.Modifier3 AS "Modifier3",
vw_ServicesXML5010.Modifier4 AS "Modifier4",
vw_ServicesXML5010.From_Date AS "From_Date",
vw_ServicesXML5010.To_Date AS "To_Date",
vw_ServicesXML5010.Revenue_Code AS "Revenue_Code",
vw_ServicesXML5010.Place_Of_Service AS "Place_Of_Service",
vw_ServicesXML5010.Taxonomy_Code AS "Taxonomy_Code"
FROM
vw_ServicesXML5010
WHERE
vw_ServiceFacilityXML5010.Service_Facility_NPI = vw_ServicesXML5010.Service_Facility_NPI
and vw_ServiceFacilityXML5010.County_Code = vw_ServicesXML5010.County_Code
and vw_ServiceFacilityXML5010.Billing_EIN = vw_ServicesXML5010.Billing_EIN
-- and vw_ServiceFacilityXML5010.County_Code in ('01', '02')
-- and vw_ServiceFacilityXML5010.Service_Facility_NPI = '1932328580'
FOR XML PATH('Service'), TYPE , ELEMENTS XSINIL
)
FROM
vw_ServiceFacilityXML5010
WHERE
vw_ServiceFacilityXML5010.County_Code = vw_OwnerXML5010.County_Code
and vw_ServiceFacilityXML5010.Billing_EIN = vw_OwnerXML5010.Billing_EIN
-- and vw_ServiceFacilityXML5010.County_Code in ( '01', '02')
-- and vw_ServicesXML5010.Service_Facility_NPI = '1932328580'
FOR XML PATH ('TB_SERVICE_FACILITY'), TYPE
-- ) AS "BILLING_PROVIDERS/TB_BILLING_PROVIDER_FILE/TB_SERVICE_FACILITY"
--) AS "TB_BILLING_PROVIDER_FILE/TB_SERVICE_FACILITY"
--) AS "TB_BILLING_PROVIDER_FILE"
) FOR XML PATH ('TB_BILLING_PROVIDER_FILE'), TYPE
)
FROM
vw_OwnerXML5010
-- where vw_OwnerXML5010.County_Code in ('01', '02')
ORDER BY vw_OwnerXML5010.County_Code
FOR XML PATH ('TB_TRADING_PARTNER'), root('TB_BILLING_PROVIDER_FILES')
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
You might get a better response with some sample data and expected results
|
|
|
|
|
I am having a query on the Production Server, I am getting an xml out of it. For some reason there is a problem in the data that I am getting, some data is missing, but I can't easily compare and see it on the xml file what am I missing and why.
It would be easier for me if I put the same Data into Table then I can easily compare what am I missing. Or is there anyway that I can read the Data from xml file and put it into a table? I am trying but I have to create table before it seems, but I want to just import into Table like we do from excel files.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 15-May-18 13:02pm.
|
|
|
|
|
CHill60 wrote: You might get a better response with some sample data and expected results My comment still stands.
Indian143 wrote: when removed the FOR XML PATH from the query it is giving error Are you are expecting us to guess what that error might be?
There are plenty of people who would like to help you solve your problem, but you're not giving us much to go on. We do this in our spare time so expecting us to wade through the SQL to try and create some tables to match it so we can see what is being produced so we can work out how to replace the FOR XML and get appropriate results ... would take more time than most of us have available.
See Some guidelines for posting questions in the forums[^]
|
|
|
|
|
I can understand by can you please help me how can I create dummy values for the views vw_ServicesXML5010, vw_ServiceFacilityXML5010, as those views are not fetching any records, the xml is not generating those elements, is it possible to help me in that regards.
For example if I don't have any records for the View vw_ServicesXML5010 for that where condition I want to have empty value for the elements Procedure_Code, Modifier1, Modifier2, Modifier3, Modifier4, From_Date, To_Date, Revenue_Code, Place_Of_Service, Taxonomy_Code
Same thing applies to the View: vw_ServiceFacilityXML5010, if it doesn't have any records then at least one record set with empty values for the Service_Facility_NPI, County_Owned_Indicator.
Can you please help me buddy, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
I just got a requirement for a web API to an Oracle database. So I fire up an Oracle DAL from 2010 only to find the reference to System.Data.OracleClient are out of date and it is not recommended. Searching for Oracle Connection does not uncover the references required, connection strings.com was no real help.
Can someone advise me on the current references for VS 2015 to connect to Oracle please. I can't add object to the server as one article suggested just a plain read only connection is required.
[edit0]
Looks like this is the latest tool from Oracle Oracle Data Provider for .NET (ODP.NET)[^]. What a PITA,
First I need an account to download, create an account, nope email already has an account, do the forgot password thing. Ok have account not to refind the link to download.
It has to be run as admin if you want to install for all users, you are not given a choice to install for just yourself. Have to close all VS Instances. I'm betting the 2017 version does not work with 2015 and it seems like you can only have 1 version installed.
As I sit here waiting for help desk to allow me to install a .net driver I really do not like Oracle.
[/edit0]
[edit1] They have a nuget package - I hate nuget [/edit1]
Never underestimate the power of human stupidity
RAH
modified 7-May-18 3:07am.
|
|
|
|
|
Caveat, I haven't worked with Oracle since 2016.
In my experience, System.Data.OracleClient should actually work just fine, it was even getting updated with new functionality for VS2015. BUT, it might break if your Oracle DB gets updated.
Otherwise I strongly recommend to get the managed version of the driver.
It doesn't need installation and it's not sensitive to 32 or 64 bit versions, just paste the dll into the bin folder and add a few lines into the app.config.
Example below. You obviously need to correct for your version of the client.
<configSections>
<remove name="oracle.manageddataaccess.client"/>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="ORCL" descriptor="
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = my.address.net)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORCL)
)
)
"/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
<connectionStrings>
<add name="IDB" connectionString="user id=MyUser;data source=orcl;password=MyPassword;Enlist=false" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings> configSections NEEDS to be FIRST in the configfile.
|
|
|
|
|
Jörgen Andersson wrote: System.Data.OracleClient Has been deprecated in favour of Oracles ODP, I chased down a connection string that does not need tsnames.ora that works a treat.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|