Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have five tables :
DeviceInfo,DefinitionSetting,DeviceDefinitionSettingValue,DeviceSettingXref, DeviceDefinitionCategory.

DeviceInfo Has these attributes
VB
di_DeviceInfoId (Primary key)
di_LogicalDeviceId
di_DeviceDefinitionId
di_DeviceType
di_AssociationId
di_MACAddress
di_IPAddress
di_GatewayAddress
di_SubnetMask
di_LastIPAddress
di_SubnetAddress
di_HostName
di_SerialNumber
di_SysObjectID
di_Location
di_XeroxAssetNumber
di_Firmware
di_SysUpTime
di_DiscoveryDate
di_LastComm
di_IpAddressChanged
di_DiscoveryType
di_Description
di_DiscoveryMethod
di_ProtocolVersion
di_LastModified
di_HasBeenExported
di_Username
di_DNSName
di_OldMACAddress
di_SysLocation
di_LastCommAttempt
di_TimeZone
di_pwd
di_createdDate
di_StatusId
di_ServiceStatus
di_StatusDate
di_DeviceName
di_Model
di_Manufacturer
di_SoftwareVersion
di_uniqueId
di_InstanceID
di_GetStatusRecievedFromGSM
di_IconStatus


DeviceDefinitionSettingXref has these attributes:
VB
DeviceDefinitionSettingXrefID (primary key)
DeviceDefinitionID
DeviceDefinitionSettingID
DeviceDefinitionCategoryID
CreatedBy
CreatedDate
ModifiedBy
ModifiedDate


DeviceDefinitionSettingValue has these
VB
DeviceDefinitionSettingValueID (primary key)
DeviceInfoId
DeviceDefinitionSettingXrefID
DeviceDefinitionSettingId
DeviceDefinitionSettingValue
CreatedBy
CreatedDate
ModifiedBy
ModifiedDate
DeviceDefinitionSettingDefaultValue
HasBeenExportedOnce


DeviceDefinitionSetting has these:
VB
DeviceDefinitionSettingID (primary key)
SettingName
SettingDescription
IsInitialDeviceSetting
SettingNameEnum
SettingDescriptionEnum
CreatedBy
CreatedDate
ModifiedBy
ModifiedDate
IsReadOnly
ExportedToDevice
SettingLabel
DisplayOrder



and lastly
DeviceDefinitionCategory has these value

VB
DeviceDefinitionCategoryID (primary key)
DeviceDefinitionCategoryType
DeviceDefinitionCategoryName
DeviceDefinitionCategoryDescription
DeviceDefinitionCategoryNameEnum
DeviceDefinitionCategoryDescriptionEnum
CreatedBy
CreatedDate
ModifiedBy
ModifiedDate




I have to extract setting name from DeviceDefinitionSetting and setting value from DeviceDefinitionSettingValue based on the IP address passed from a certain camera which will be populated in DeviceInfo table and on basis of CategoryId which will be in DeviceDefintionCategory.


I developed this query to do the above:
XML
SELECT     DeviceDefinitionSetting.SettingName, DeviceDefinitionSettingValues.DeviceDefinitionSettingValue
FROM         DeviceDefinitionSettingValues INNER JOIN
DeviceDefinitionSetting ON DeviceDefinitionSettingValues.DeviceDefinitionSettingId = DeviceDefinitionSetting.DeviceDefinitionSettingID
INNER JOIN DeviceDefinitionSettingXref ON DeviceDefinitionSettingValues.DeviceDefinitionSettingXrefID = DeviceDefinitionSettingXref.DeviceDefinitionSettingXrefID AND
DeviceDefinitionSetting.DeviceDefinitionSettingID = DeviceDefinitionSettingXref.DeviceDefinitionSettingID INNER JOIN
DeviceDefinitionCategory ON DeviceDefinitionSettingXref.DeviceDefinitionCategoryID = DeviceDefinitionCategory.DeviceDefinitionCategoryID INNER JOIN
DeviceInfo ON DeviceDefinitionSettingValues.DeviceInfoId = DeviceInfo.di_DeviceInfoId  where di_IPAddress='<some ip address>' and DeviceDefinitionCategory.DeviceDefinitionCategoryID='<some category ID>';


But i am not sure as this would fetch me required data.
Any Suggestions or alternate query is welcomed
Posted
Comments
Magic Wonder 27-Jun-14 6:49am    
Have you tried to run your query? Try to run your query, check whether you are getting the desired output or not. If not then try to modify your query to get desired output.
Anshumaan Chaturvedi 27-Jun-14 6:59am    
I have but duplication arises. I mainly wanted to have a review.

1 solution

Please confirm by running the query once again. If the duplicate records are because there are duplicate values, in that case a top 1/distinct with a group by condition will help you eliminate the duplicates.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900