Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a stored procedure:
USE [XDMLite]
GO
/****** Object: StoredProcedure [dbo].[usp_getDeviceDefinition] Script Date: 08/07/2014 23:43:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery67.sql|7|0|C:\Users\c5038671\AppData\Local\Temp\~vs2722.sql
ALTER PROCEDURE [dbo].[usp_getDeviceDefinition]
(
@deviceInfoId int
)

AS


SET NOCOUNT ON
SELECT 'Settings' AS Section, ddsref.DeviceDefinitionID, ddsref.DeviceDefinitionSettingID,
ddsref.DeviceDefinitionCategoryID, dds.SettingName,dds.SettingDescription,
dds.IsInitialDeviceSetting, sdt.DefaultValue, sdt.MaximumLength, sdt.RegularExpression,
sdt.MinimumValue, sdt.MaximumValue,sdt.EnumValue,ddsv.DeviceDefinitionSettingValueID,
ddsv.HasBeenExportedOnce,ddsv.DeviceDefinitionSettingDefaultValue, dt.DataTypeName,
NULL AS DeviceCommunication, NULL AS UserAuthenticationType, NULL AS SoftwareVersion,
NULL AS DeviceType, NULL AS Model, NULL AS Manufacturer, NULL AS DeviceDefinitionCategoryType,
NULL AS DeviceDefinitionCategoryName, NULL AS DeviceDefinitionCategoryDescription,
NULL AS CreatedDate,dds.IsReadOnly,dds.SettingLabel,dds.DisplayOrder
FROM DeviceDefinitionSettingXref AS ddsref
INNER JOIN DeviceDefinitionSetting AS dds ON
dds.DeviceDefinitionSettingID = ddsref.DeviceDefinitionSettingID
INNER JOIN DeviceDefinitionSettingValues as ddsv ON
ddsv.DeviceDefinitionSettingXrefID=ddsref.DeviceDefinitionSettingXrefID AND
ddsv.DeviceDefinitionSettingId=dds.DeviceDefinitionSettingID AND
ddsv.DeviceInfoId=@deviceInfoId
INNER JOIN SettingDataType AS sdt ON
sdt.DeviceDefinitionSettingId = dds.DeviceDefinitionSettingID
INNER JOIN DataType AS dt ON dt.DataTypeID = sdt.DataTypeID
INNER JOIN DeviceDefinition AS dd ON
dd.DeviceDefinitionID = ddsref.DeviceDefinitionID
INNER JOIN DeviceInfo AS di ON
di.di_DeviceType = dd.DeviceType AND
di.di_Model = dd.Model AND di.di_Manufacturer = dd.Manufacturer
WHERE (di.di_DeviceInfoId = @deviceInfoId AND DeviceDefinitionCategoryID not in('7E792E2F-B488-4C9F-A811-9E12501EA6A9','896FC890-A386-4D40-8051-1D0F3120F1C0')
AND dd.DeviceDefinitionID = di.di_DeviceDefinitionId)
UNION
SELECT 'Categories' AS Section, ddsXref.DeviceDefinitionID, NULL AS DeviceDefinitionSettingID,
ddc.DeviceDefinitionCategoryID, NULL AS SettingName, NULL AS SettingDescription,
NULL AS IsInitialDeviceSetting, NULL AS DefaultValue, NULL AS MaximumLength,
NULL AS RegularExpression, NULL AS MinimumValue, NULL AS MaximumValue, NULL AS EnumValue,
NULL as DeviceDefinitionSettingValueID,NULL as HasBeenExportedOnce,
NULL as DeviceDefinitionSettingDefaultValue,NULL AS DataTypeName, NULL AS DeviceCommunication,
NULL AS UserAuthenticationType, NULL AS SoftwareVersion, NULL AS DeviceType, NULL AS Model,
NULL AS Manufacturer, ddc.DeviceDefinitionCategoryType,ddc.DeviceDefinitionCategoryName,
ddc.DeviceDefinitionCategoryDescription, NULL AS CreatedDate,NULL AS IsReadOnly,NULL AS SettingLabel,
NULL AS DisplayOrder
FROM DeviceDefinitionCategory AS ddc
INNER JOIN DeviceDefinitionSettingXref as ddsXref ON
ddsXref.DeviceDefinitionCategoryID=ddc.DeviceDefinitionCategoryID
INNER JOIN DeviceDefinition AS dd ON
dd.DeviceDefinitionID = ddsXref.DeviceDefinitionID
INNER JOIN DeviceInfo AS di ON
di.di_DeviceType = dd.DeviceType AND
di.di_Model = dd.Model AND
di.di_Manufacturer = dd.Manufacturer
WHERE (di.di_DeviceInfoId = @deviceInfoId AND ddc.DeviceDefinitionCategoryID not in('7E792E2F-B488-4C9F-A811-9E12501EA6A9','896FC890-A386-4D40-8051-1D0F3120F1C0')
AND dd.DeviceDefinitionID = di.di_DevicedefinitionId)
UNION
SELECT 'DeviceDefinition' AS Section, dd.DeviceDefinitionID, NULL AS DeviceDefinitionSettingID,
NULL AS DeviceDefinitionCategoryID, NULL AS SettingName, NULL AS SettingDescription,
NULL AS IsInitialDeviceSetting, NULL AS DefaultValue, NULL AS MaximumLength,
NULL AS RegularExpression, NULL AS MinimumValue, NULL AS MaximumValue, NULL AS EnumValue,
NULL as DeviceDefinitionSettingValueID,NULL as HasBeenExportedOnce,
NULL as DeviceDefinitionSettingDefaultValue, NULL AS DataTypeName, dd.DeviceCommunication,
dd.UserAuthenticationType,dd.SoftwareVersion, dd.DeviceType, dd.Model, dd.Manufacturer,
NULL AS DeviceDefinitionCategoryType, NULL AS DeviceDefinitionCategoryName,
NULL AS DeviceDefinitionCategoryDescription, dd.CreatedDate,NULL AS IsReadOnly,
NULL AS SettingLabel,NULL AS DisplayOrder
FROM DeviceDefinition AS dd
INNER JOIN DeviceInfo AS di ON
di.di_DeviceType = dd.DeviceType AND
di.di_Model = dd.Model AND
di.di_Manufacturer = dd.Manufacturer
WHERE (di.di_DeviceInfoId = @deviceInfoId
and dd.DeviceDefinitionID = di.di_DevicedefinitionId)

RETURN

Here, there are following three major tables:
DeviceDefinition
DeviceInfo
DeviceDefinitionSettingXref

Now, this stored procedure returns the information associated with Device.
Problem is when i have updated the DeviceDefinitionId in DeviceDefinition table,
the data is also present in DeviceDefinitionSettingXref and in DeviceInfo table.
But, when i execute the stored procedure it does not give me the desired result

I wanted to do a quick debugging to see what values are there while this procedure is executed. How can i do that.?
Posted

You can use the PRINT command to send info to the message window in Management Studio

SQL
PRINT 'Test'


or

SQL
PRINT @deviceInfoId
 
Share this answer
 
Hello ,
First of all remove the no of columns in select statement as far as possible.
Consider It in no of parts..Then consider without union the first part.
for example
SQL
SELECT 'Settings' AS Section, ddsref.DeviceDefinitionID, ddsref.DeviceDefinitionSettingID,
ddsref.DeviceDefinitionCategoryID, dds.SettingName,dds.SettingDescription,
dds.IsInitialDeviceSetting, sdt.DefaultValue, sdt.MaximumLength, sdt.RegularExpression,
sdt.MinimumValue, sdt.MaximumValue,sdt.EnumValue,ddsv.DeviceDefinitionSettingValueID,
ddsv.HasBeenExportedOnce,ddsv.DeviceDefinitionSettingDefaultValue, dt.DataTypeName,
NULL AS DeviceCommunication, NULL AS UserAuthenticationType, NULL AS SoftwareVersion,
NULL AS DeviceType, NULL AS Model, NULL AS Manufacturer, NULL AS DeviceDefinitionCategoryType,
NULL AS DeviceDefinitionCategoryName, NULL AS DeviceDefinitionCategoryDescription,
NULL AS CreatedDate,dds.IsReadOnly,dds.SettingLabel,dds.DisplayOrder
FROM DeviceDefinitionSettingXref AS ddsref
INNER JOIN DeviceDefinitionSetting AS dds ON
dds.DeviceDefinitionSettingID = ddsref.DeviceDefinitionSettingID
INNER JOIN DeviceDefinitionSettingValues as ddsv ON
ddsv.DeviceDefinitionSettingXrefID=ddsref.DeviceDefinitionSettingXrefID AND
ddsv.DeviceDefinitionSettingId=dds.DeviceDefinitionSettingID AND
ddsv.DeviceInfoId=@deviceInfoId
INNER JOIN SettingDataType AS sdt ON
sdt.DeviceDefinitionSettingId = dds.DeviceDefinitionSettingID
INNER JOIN DataType AS dt ON dt.DataTypeID = sdt.DataTypeID
INNER JOIN DeviceDefinition AS dd ON
dd.DeviceDefinitionID = ddsref.DeviceDefinitionID
INNER JOIN DeviceInfo AS di ON
di.di_DeviceType = dd.DeviceType AND
di.di_Model = dd.Model AND di.di_Manufacturer = dd.Manufacturer
WHERE (di.di_DeviceInfoId = @deviceInfoId AND DeviceDefinitionCategoryID not in('7E792E2F-B488-4C9F-A811-9E12501EA6A9','896FC890-A386-4D40-8051-1D0F3120F1C0')
AND dd.DeviceDefinitionID = di.di_DeviceDefinitionId)


then consider second part .
SQL
SELECT 'Categories' AS Section, ddsXref.DeviceDefinitionID, NULL AS DeviceDefinitionSettingID,
ddc.DeviceDefinitionCategoryID, NULL AS SettingName, NULL AS SettingDescription,
NULL AS IsInitialDeviceSetting, NULL AS DefaultValue, NULL AS MaximumLength,
NULL AS RegularExpression, NULL AS MinimumValue, NULL AS MaximumValue, NULL AS EnumValue,
NULL as DeviceDefinitionSettingValueID,NULL as HasBeenExportedOnce,
NULL as DeviceDefinitionSettingDefaultValue,NULL AS DataTypeName, NULL AS DeviceCommunication,
NULL AS UserAuthenticationType, NULL AS SoftwareVersion, NULL AS DeviceType, NULL AS Model,
NULL AS Manufacturer, ddc.DeviceDefinitionCategoryType,ddc.DeviceDefinitionCategoryName,
ddc.DeviceDefinitionCategoryDescription, NULL AS CreatedDate,NULL AS IsReadOnly,NULL AS SettingLabel,
NULL AS DisplayOrder
FROM DeviceDefinitionCategory AS ddc
INNER JOIN DeviceDefinitionSettingXref as ddsXref ON
ddsXref.DeviceDefinitionCategoryID=ddc.DeviceDefinitionCategoryID
INNER JOIN DeviceDefinition AS dd ON
dd.DeviceDefinitionID = ddsXref.DeviceDefinitionID
INNER JOIN DeviceInfo AS di ON
di.di_DeviceType = dd.DeviceType AND
di.di_Model = dd.Model AND
di.di_Manufacturer = dd.Manufacturer
WHERE (di.di_DeviceInfoId = @deviceInfoId AND ddc.DeviceDefinitionCategoryID not in('7E792E2F-B488-4C9F-A811-9E12501EA6A9','896FC890-A386-4D40-8051-1D0F3120F1C0')
AND dd.DeviceDefinitionID = di.di_DevicedefinitionId)



then consider 3rd part. Try to combine the first part & second part. then 3rd part .this may get you closer to your desired output
If Not Getting then try the join with less number of tables .
.keep patience while debugging.
Happy Coding :-)
 
Share this answer
 
v3

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