|
If you plan to split the databases in the future there might be a point to it.
Or if you want to give different people different access, but there are easier ways to achieve that.
|
|
|
|
|
No the databases are already split into 3
Users
Data
Log
I was asked if there was merit to different logons for the website to the databases (via services) but couldn't find a suitable answer so thought I'd ask her as someone may know of a good practise or had experience.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Hi all,
I have a joins select statement, what I want is, if I am having same tables in two left joins and with exclusive Data then in another table when we are joining Data in ON clause I want to be able to Join one or the other table to get the Data, maybe like a case statement but joining one table in condition over the other.
Here is the example:
<pre>DECLARE @AdminAddressTypeId int
SET @AdminAddressTypeId = (select top 1 AddType.PKAddressTypeLKPId from AddressTypeLKP AddType where AddType.Description = 'Administrative')
SELECT LE.LegalEntityName
,LE.PKLegalEntityId
,LE.FederalTaxId
,LE.LegalEntityNbr
-- ,LE.LegalEntityBgnDt
-- ,LE.LegalEntityEndDt
-- ,LE.CreatedDate
-- ,LE.CreatedBy
-- ,LE.ModifiedDate
-- ,LE.ModifiedBy
-- ,OW.Description as OwnershipType
--,OW.Code +'-'+ OW.Description as OwnershipType
--,LE.FKOwnershipTypeLKPId
--,MGMT.Description as ManagementType
--,LE.FKManagementTypeLKPId
,PRG.Description as ProgramType
,LE.FKProgramTypeLKPId
--,C.County_Name as CountyName
,C.PK_Geographic_Location_Code + '-' + C.County_Name as CountyName
,LE.FKCountyLKPId
,AA.StreetAddress1
,AA.City
,Admin_S.State_Name
,AA.Zip1
-- ,LE.IsCompleted
--,LE.Comments
--,LET.Description as LegalEntityType
FROM [dbo].[LegalEntity] LE
-- left outer join [dbo].[OwnershipTypeLKP] OW ON LE.FKOwnershipTypeLKPId = OW.PKOwnershipTypeLKPId
-- left outer join [dbo].[ManagementTypeLKP] MGMT ON LE.FKManagementTypeLKPId = MGMT.PKManagementTypeLKPId
inner join [dbo].[ProgramTypeLKP] PRG on LE.FKProgramTypeLKPId = PRG.PKProgramTypeLKPId and PRG.Description = 'Mental Health'
left outer Join [dbo].County C on LE.FKCountyLKPId = C.PKCountyId
--left outer join [dbo].[LegalEntityTypeLKP] LET on LE.FKLegalEntityTypeLKPId = LET.PKLegalEntityTypeLKPId
Left outer join LegalEntityAddress LEA_Admin on LE.PKLegalEntityId = LEA_Admin.FKLegalEntityId and LEA_Admin.FKAddressTypeLKPId = @AdminAddressTypeId and LEA_Admin.IsValid = 1 and ( LEA_Admin.EffectiveDateTo is null or LEA_Admin.EffectiveDateTo > getdate())
--(case when @AAEffectiveDateTo ='' then 0 else @AAEffectiveDateTo end)
left Outer JOIN Address AA ON LEA_Admin.FKAddressId = AA.PKAddressId
Left outer JOIN County Admin_CY on Admin_CY.PKCountyId = AA.FK_County
Left outer join State Admin_S on Admin_S.PKStateId = AA.FK_State
where LE.IsCompleted = 1
What I want is I am checking for only LegalEntityAddress that are Admins, but if Admin Address is not available for that Legal Entity I want to display any address that has the latest closing Date, if it doesn't find any data for these two conditions then I want any first date that's available or the one with highest PK value.
If I can achieve this by having one time join of the table that will be nice if I can't get it by using one same table join or need same table to be joined multiple times, please help me how can I achieve it. If I need to have LegalEntityAddress multiple joins with different conditions then how can I handle that situation in further down tables which are using this LegalEntityAddress reference table to join.
Any help would be very helpful, thanks in advance.
|
|
|
|
|
I think you are going to need multiple joins to the same table and use nested ISNULL conditions.
However your requirement to pick the latest valid address due to different conditions is going to make this a nightmare in a single pass. I would split that logic out to a view that encapsulates the rules and supplies a single address for each entity. Then simply inner join to the view. Make the view generic and you have it available for any procedure
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Yeah I did it using table valued functions - thanks for giving me the idea, here is my script for it.
create FUNCTION udf_GetLegalEntityAddress(@leId int)
returns @T table(PKAddressId int,
StreetAddress1 varchar(75),
StreetAddress2 varchar(75),
City varchar(75),
FK_County int,
FK_State int,
Zip1 int,
Zip2 int,
CreatedDate datetime,
CreatedBy varchar(500),
ModifiedDate datetime,
ModifiedBy varchar(500),
MigrationNotes varchar(50),
FKProgramTypeLKPId int,
OldSystemId int,
ValidFlag bit)
AS
begin
DECLARE @AdminAddressTypeId int=0, @AddressId int=0, @effectivedate datetime, @PKLegalEntityAddressId int
SET @AdminAddressTypeId = (select top 1 AddType.PKAddressTypeLKPId from AddressTypeLKP AddType where AddType.Description = 'Administrative')
SET @AddressId =
(select top 1 FKAddressId from LegalEntityAddress where FKAddressTypeLKPId= @AdminAddressTypeId and FKLegalEntityId=@leId and IsValid = 1)
if ((@AddressId is null) or (@AddressId=0))
begin
SET @AddressId =
(select top 1 FKAddressId from LegalEntityAddress where (EffectiveDateTo is null) and FKLegalEntityId=@leId and IsValid = 1)
end
if ((@AddressId is null) or (@AddressId=0))
begin
set @effectivedate = (select max(EffectiveDateTo) from LegalEntityAddress where FKLegalEntityId=@leId and (IsValid = 1))
if ((@effectivedate is null) or (@effectivedate<='1900-01-01'))
begin
set @PKLegalEntityAddressId = (select max(PKLegalEntityAddressId) from LegalEntityAddress where (FKLegalEntityId=@leId) and (IsValid = 1))
SET @AddressId =
(select top 1 FKAddressId from LegalEntityAddress where PKLegalEntityAddressId=@PKLegalEntityAddressId)
end
else
begin
SET @AddressId =
(select top 1 FKAddressId from LegalEntityAddress where FKLegalEntityId=@leId and EffectiveDateTo=@effectivedate)
end
end
if ((@AddressId is null) or (@AddressId=0))
begin
SET @AddressId =
(select top 1 FKAddressId from LegalEntityAddress where FKLegalEntityId=@leId and IsValid = 1)
end
insert into @T (
PKAddressId,
StreetAddress1,
StreetAddress2,
City,
FK_County,
FK_State,
Zip1,
Zip2,
CreatedDate,
CreatedBy,
ModifiedDate,
ModifiedBy,
MigrationNotes,
FKProgramTypeLKPId,
OldSystemId,
ValidFlag)
select top 1
PKAddressId,
StreetAddress1,
StreetAddress2,
City,
FK_County,
FK_State,
Zip1,
Zip2,
CreatedDate,
CreatedBy,
ModifiedDate,
ModifiedBy,
MigrationNotes,
FKProgramTypeLKPId,
OldSystemId,
ValidFlag from [Address] where PKAddressId=@AddressId
RETURN
end
go
Then using it in the stored Procedure using Outer Apply
SELECT LE.LegalEntityName
,LE.PKLegalEntityId
,LE.FederalTaxId
,LE.LegalEntityNbr
,PRG.Description as ProgramType
,LE.FKProgramTypeLKPId
,C.PK_Geographic_Location_Code + '-' + C.County_Name as CountyName
,LE.FKCountyLKPId
,AA.StreetAddress1
, AA.City
,Admin_S.State_Name
,AA.Zip1
FROM [dbo].[LegalEntity] LE
inner join [dbo].[ProgramTypeLKP] PRG on LE.FKProgramTypeLKPId = PRG.PKProgramTypeLKPId and PRG.Description = 'Mental Health'
left outer Join [dbo].County C on LE.FKCountyLKPId = C.PKCountyId
outer apply dbo.udf_GetLegalEntityAddress(LE.PKLegalEntityId) AS LEA
left Outer JOIN Address AA ON LEA.PKAddressId = AA.PKAddressId
Left outer JOIN County Admin_CY on Admin_CY.PKCountyId = AA.FK_County
Left outer join State Admin_S on Admin_S.PKStateId = AA.FK_State
where LE.IsCompleted = 1
|
|
|
|
|
Neat solution, does it make any difference if your function if you function simply returns the AddressID and then you join the to that ID - I'm not advocating it just curious.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Thank you, sorry late but least I understood it now, what you are saying is right, but if that gives me extra performance I am sure I would do it, but what I thought was that, I will need another join for it - I am not sure which one is better in performance wise, if you are familiar please let me know my friend. Thanks a lot my friend
modified 13-Nov-18 18:51pm.
|
|
|
|
|
I have an older vb win app that I wrote in VS2013 because I have install shield that supports it. I used LocalDB for the database and it worked fine. But LocalDB is pretty heavy, I had to write an automated script to install it first, and then used old school TSQL to make the calls.
So the customer asked me to upgrade it, make it more modern. I choose SQLite, but EF6 doesn't support migrations or table creation. I really don't want to write older code to support it. Now I'm looking for something else to use. Would like to use MongoDB but them I have to wrote code to install it first which may be easier than using SQLite.
On .Net Core, SQLite works great, and I heard some .Net Core features will be available for win apps.
Any Suggestions?
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
LiteDB is a no-install object store for .NET. It's effectively a no-install Mongo.
I've used it for relatively small-scale applications with success (relatively few collections, up to a few hundred thousand records per collection).
Mind you, object stores are not necessarily the right answer if the data is heavily relational; you might want to stick with LocalDB and optimize your queries.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
I'll take a look at that.
I just have 4 tables that store account names, manufactures and product with a join to pricing.
About 500 products, and pricing for every product and account. So the pricing may grow large.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Both VB and C# contain a way of testing mutually exclusive possibilities, the Select Case and Switch clauses respectively. Only one of them works properly.
A Visual Basic Select Case clause, returning a description of how old someone is. The age range for a young person is a tad generous, reflecting the age of the author of this article.
|
|
|
|
|
Hi,
I have taken a backup of one Database DBa, then I created a new Database that's DBb, I tried to restore the Database DBb, message says Database restored successfully but still the new DBb doesn't get any Tables, Views or SPs in to this new Database DBb.
When I am taking the backup options that I have taken are as below:
in General tab, 1. Backup Type: Full 2. Copy only Backup in Options tab: 1. Backup set will expire: I have taken more than 1000 or 100 max number
In the restore I have taken the options of:
Restore -> Database in that In General Tab: Selected "Device" then selected the file
In Options tab: 1. Overwrite existing Database 2. Close existing connections.
Then OK,
Is there any mistake I did either in taking the backup or in restoring the Db, but the message says, the Database is restored successfully but restore doesn't create any tables views or any object of the backup file, I am not understanding, any help would be greatly helpful, please, the message is so misleading for me. Thanks in advance
modified 8-Nov-18 12:35pm.
|
|
|
|
|
Hello,
I have a column in table that have nvarchar(200) datatype
and then I add index on another column include my nvarchar(200) column
but the performance is the same when I do a select query with where condition in the nvarchar(200) column
I need to know why the index on nvarchar column doesn't affect the performance?
|
|
|
|
|
|
IS there any explanation for this ?
|
|
|
|
|
|
Message Removed
modified 9-Nov-18 11:29am.
|
|
|
|
|
hi
please help me i have a project, need to write a code in ms access or python to do the able to press a button on the form windscreen that scans an image into my database field.
|
|
|
|
|
|
Have you contacted the manufacturer of said scanner and asked them how to interact with it programmatically? Probably through an API that they would have to provide.
As things stand, I could probably tell you how to interact with my old scanner - but you can bet your bottom dollar it won't work for yours. So more detail would be needed.
As an aside, storing the actual scanned image onto your "database field" is probably going to be a very bad idea. The Access file is going to get very big very quickly. You should consider storing the image on the file system (it's what it is designed for) and storing a link to it on the database itself (hint - using explicit paths or drive mappings is not a good idea - a rather bitter experience with FileNet proved this to me in the past)
|
|
|
|
|
the database program consith of the following fields
Name
Surname
Scanned document of The Person
Please help i am new to programming i do not want to loose hope!
|
|
|
|
|
Quote: Have you contacted the manufacturer of said scanner and asked them how to interact with it programmatically? Probably through an API that they would have to provide.
If you are new to programming then getting a scanner to work through an API is probably beyond your current capabilities.
Your table (it is not a database) should also include a unique identifier for the person (after all, people can have the same name).
Do not store the actual document on the database, store it's relative path or it's path relative to a fixed folder name.
|
|
|
|
|
HI
I NEED HELP IN TRYING TO WRITE DATABSE PROGRAM TO IN ACCESS OR PYTHON CAPTURE THE NAME, ID NUMBER, ADDRESS, PHONE NUMBER, AND FIELD TO ABLE TO SCAN DOCUMENT TO FROM A FLAT BED SCANNER TO MY ACCESS DATABSE FIELD.
WHEN I PRESS A BUTTON ON THE FORM. I AM STILL LEARNING PYTHON AND ACCESS
PLEASE HELP
|
|
|
|
|
|
Scenario:
one User1 press the save gets the last number 1000012 on the header then Run SP for Details saving(with 3 detail line items)
at the same time user2 press the save gets 1000013 on the header then Run SP for Details saving
(with 1 detail line items)
after checking after checking users inserted
user1 has 4 lines
user2 has 0 lines
ALTER PROCEDURE [dbo].[sp_HeaderSave] (@Lastnumber Decimal) AS
BEGIN
INSERT INTO Header (DOCNo, VersionNo, NoteDate)
VALUES (@Lastnumber,'VersionNo',GETDATE())
END
ALTER PROCEDURE [dbo].[sp_DetailSave] (@Lastnumber Decimal) AS
BEGIN
INSERT INTO Detail(DOCNo, ItemNo, Qty)
VALUES (@Lastnumber,'Items One',12)
END
thank you,
|
|
|
|
|