Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dilipd006
Starting Member
4 Posts |
Posted - 2010-11-22 : 05:27:59
|
deleted |
|
dilipd006
Starting Member
4 Posts |
Posted - 2010-11-22 : 05:49:14
|
deleted |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-12-13 : 07:21:05
|
quote: Originally posted by dilipd006 Hi i have a table [ApplicationConfig]CREATE TABLE [dbo].[ApplicationConfig]( [ConfigID] [smallint] IDENTITY(1,1) NOT NULL, [ConfigName] [varchar](30) NOT NULL, [ConfigValue] [varchar](250) NOT NULL, [IsActive] [bit] NOT NULL, CONSTRAINT [PK_ApplicationConfig] PRIMARY KEY CLUSTERED ( [ConfigID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOIn this ConfigID is PK ConfigName can have multiple ConfigValue but only different values are addedSample DataConfigID [ConfigName] [ConfigValue] [IsActive]1 Currency INR 12 Currency USD 03 Currency AD 0this is a multiple row insert..so insertin with the help of xml<ApplicationConfig><ConfigValue><Value>INR</Value><IsActive>1</IsActive></ConfigValue><ConfigValue><Value>USD</Value><IsActive>0</IsActive></ConfigValue></ApplicationConfig>the stored procedure is belowCREATE PROCEDURE [dbo].[uspAppConfigurationInsert]( @vchConfigName varchar(30) ,@xmlAppConfig XML ,@tintStatus tinyint OUTPUT ,@vchStatusMessage varchar(50) OUTPUT)ASBEGIN SET NOCOUNT ON; SET @vchStatusMessage = '' BEGIN IF EXISTS(-- HERE the validation done to check whether the value exist for this ConfigName or not SELECT 1 FROM [dbo].[ApplicationConfig] WHERE ConfigName = @vchConfigName AND ConfigValue IN (SELECT V.y.value('./text()[1]','varchar(250)') FROM @xmlAppConfig.nodes('/ApplicationConfig/ConfigValue/Value') as V(y)) ) BEGIN SET @tintStatus=1 SET @vchStatusMessage = 'ConfigValue already exist for this ConfigName' RETURN; -- Returns due to duplication END END INSERT INTO [dbo].[ApplicationConfig] ( ConfigName ,ConfigValue ,IsActive ) SELECT @vchConfigName ,V.y.value('(.//Value)[1]','varchar(250)') AS ConfigValue ,V.y.value('(.//IsActive)[1]','bit') AS IsActive FROM @xmlAppConfig.nodes('/ApplicationConfig/ConfigValue') as V(y) SET @tintStatus = 0 --success RETURN;ENDthe procedure insert the value and validate the ConfigValue from the XML tag whether the value exist or not...it will check the whole ConfigValue Elment in the XML and if any ConfigValue is present in the tag it will give an message..what i want...i want to know which ConfigValue tag is present so that i pass them to the frontend that this tag is already present..Currently it is jst passing the message that ConfigValue is already present not ConfigValue elementThank you in advanceWith regards DD
It's not clear what you want. N 56°04'39.26"E 12°55'05.63" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-12-13 : 07:22:12
|
quote: Originally posted by dilipd006 Here is the data to execute DECLARE @x xmlSET @x = '<ApplicationConfig> <ConfigValue> <Value>INR</Value> <IsActive>1</IsActive> </ConfigValue> <ConfigValue> <Value>USD</Value> <IsActive>0</IsActive> </ConfigValue> </ApplicationConfig>'DECLARE @return_value int, @tintStatus tinyint, @vchStatusMessage varchar(50)EXEC @return_value = [dbo].[usp_OTM_WS_AppConfigurationInsert] @vchConfigName = N'Currency', @xmlAppConfig = @x, @tintStatus = @tintStatus OUTPUT, @vchStatusMessage = @vchStatusMessage OUTPUTSELECT @tintStatus as N'@tintStatus', @vchStatusMessage as N'@vchStatusMessage'SELECT 'Return Value' = @return_valueGO -- this one execute and insert the Config value into the table --however when i tried to insert the with one new data and one old data--it doesn't insert even though there is one new data..--I just want to display the duplicated data that are pesent in the tag.--below is the new xml after the first xml insertion<ApplicationConfig> <ConfigValue> <Value>AD</Value> --new value to insert <IsActive>1</IsActive> </ConfigValue> <ConfigValue> <Value>USD</Value> -- duplicate value to display <IsActive>0</IsActive> </ConfigValue> <ConfigValue> <Value>INR</Value> -- duplicate value to display <IsActive>1</IsActive> </ConfigValue></ApplicationConfig>
Aha. This makes more sense. You can use MERGE statement in your procedure to deal with both inserts (new records) and updates (existing records).MERGE is a new feature of SQL Server 2008. N 56°04'39.26"E 12°55'05.63" |
|
|
|
|
|
|
|