Tuesday, September 3, 2013

[T-SQL] help me for Find and replace

[T-SQL] help me for Find and replace


help me for Find and replace

Posted: 03 Sep 2013 12:49 AM PDT

i have the following strucrue and the data as folloows[code]DECLARE @DetTbl AS TABLE (id INT IDENTITY (1, 1), Detail NVARCHAR (500))DECLARE @Data AS TABLE (id INT IDENTITY (1, 1), DetVal NVARCHAR (500), Detid INT)INSERT INTO @DetTblVALUES ('Data1 is a Data2'), ('Data3 is Not a Data1')INSERT INTO @DataVALUES ( '<keys> <Key> <KeyID>Data1</KeyID> <KeyVal>Cow</KeyVal> </Key> <Key> <KeyID>Data2</KeyID> <KeyVal>Animal</KeyVal> </Key></keys>', 1 ),( '<keys> <Key> <KeyID>Data1</KeyID> <KeyVal>Parrot</KeyVal> </Key> <Key> <KeyID>Data2</KeyID> <KeyVal>Bird</KeyVal> </Key></keys>', 1),( '<keys> <Key> <KeyID>Data3</KeyID> <KeyVal>Table</KeyVal> </Key> <Key> <KeyID>Data1</KeyID> <KeyVal>Animal</KeyVal> </Key></keys>', 2)[/code]I want the result as follows[code]Cow is a AnimalParrot is a BirdTable is Not a Animal [/code]so for i have down this[code];WITH cte AS ( SELECT d.id, CAST (d.DetVal AS XML) AS DetVal, d.Detid, dt.Detail FROM @Data d INNER JOIN @DetTbl dt ON dt.id = d.Detid),x AS(SELECT detail, kid, kvalueFROM cte d CROSS APPLY( SELECT a.b.value ('KeyID[1]', 'varchar(100)') AS KID, a.b.value ('KeyVal[1]', 'varchar(100)') AS KValue FROM DetVal.nodes ('keys/Key') AS a (b) )x)SELECT * FROM x[/code]any idea

How to insert multiple rows into a table with identity column

Posted: 04 Jan 2012 12:39 AM PST

Hi,I am having trouble inserting the multiple rows into a table with identity column. The error i get is...An explicit value for the identity column in table can only be specified when a column list is used and identity insert is ON

Table dependencies

Posted: 02 Sep 2013 05:01 PM PDT

Hi, I want to get the list of dependency tables(through all the levels ie child of child) that are depends on the parent table using T-SQL.

IF Statement based on Multiple SELECT Statements

Posted: 02 Sep 2013 02:33 AM PDT

HiBasically, I'm attempting to write a statement based on multiple conditions. So, there will be 2 SELECT statements, IF the results of the first SELECT statement exist in the results of the second SELECT statement, then the script must execute a SP. Is this possible to do?

No comments:

Post a Comment

Search This Blog