I migrated some 20,000 nodes from d6 to d7 and when i check on the front end some node of content is not present so i would like to know the query to check the node id whose content is null or empty...
If by content you mean node body, then run
"SELECT entity_id FROM `field_data_body` WHERE body_value is Null"
Related
I have a table in SQL Server with an XML column:
CREATE TABLE dbo.XmlData (
id INT IDENTITY,
data XML
);
The XML stored in the data column is dynamic, I mean, only some of them have certain child node. Additionally, this nodes appear in different locations within the XML structure.
Example 1, /RootNode/FindMe:
<RootNode>
<ChildNodeOne>One</ChildNodeOne>
<ChildNodeTwo>Two</ChildNodeTwo>
<ChildNodeThree>Three</ChildNodeThree>
<FindMe>FindMe</FindMe>
</RootNode>
Example 2, /RootNode/ChildNodeThree/Deeper/FindMe and /RootNode/ChildNodeTwo/FindMe :
<RootNode>
<ChildNodeOne>One</ChildNodeOne>
<ChildNodeTwo>
<FindMe>FindMe</FindMe>
</ChildNodeTwo>
<ChildNodeThree>
<Deeper>
<FindMe>FindMe</FindMe>
</Deeper>
</ChildNodeThree>
</RootNode>
There are rows with the XML column that doesn't have the <FindMe/> node.
I need to write a query to retrieve only the rows that have the <FindMe/> node. No matter its location within the XML structure.
The first thing to know is, that //FindMe will trigger a deep search. That means: Find this node whereever it exists in the XML. A single / marks the root element (Start the search at the beginning) and no slash at all marks the current node (Continue from the context node):
In the following there are some examples how one could query for a node name:
A dummy table for tests:
CREATE TABLE dbo.DummyTbl (
id INT IDENTITY,
Remark VARCHAR(100),
data XML
);
INSERT INTO DummyTbl VALUES
('FindMe is on second level',
'<RootNode>
<ChildNodeOne>One</ChildNodeOne>
<ChildNodeTwo>Two</ChildNodeTwo>
<ChildNodeThree>Three</ChildNodeThree>
<FindMe>FindMe 1</FindMe>
</RootNode>')
,('FindMe is two times somewhere deeper',
'<RootNode>
<ChildNodeOne>One</ChildNodeOne>
<ChildNodeTwo>
<FindMe>FindMe 2a</FindMe>
</ChildNodeTwo>
<ChildNodeThree>
<Deeper>
<FindMe>FindMe 2b</FindMe>
</Deeper>
</ChildNodeThree>
</RootNode>')
,('FindMe does not exist',
'<RootNode>
<ChildNodeOne>One</ChildNodeOne>
<ChildNodeTwo>
</ChildNodeTwo>
<ChildNodeThree>
<Deeper>
<FindMeNot>Something else</FindMeNot>
</Deeper>
</ChildNodeThree>
</RootNode>')
,('FindMe exists, but is empty',
'<RootNode>
<ChildNodeOne>One</ChildNodeOne>
<ChildNodeTwo>
</ChildNodeTwo>
<ChildNodeThree>
<Deeper>
<FindMe/>
</Deeper>
</ChildNodeThree>
</RootNode>');
Different queries:
--All FindMe nodes (inlcuding the empty one)
SELECT d.id,d.Remark
,f.value('.','nvarchar(max)') FindMeNode
FROM dbo.DummyTbl AS d
CROSS APPLY d.data.nodes('//FindMe') AS A(f)
--All IDs where there is at least one "FindMe"-node
SELECT d.id,d.Remark
FROM dbo.DummyTbl AS d
WHERE d.data.exist('//FindMe')=1
GO
--All IDs where there is at least one "FindMe"-node, but not the empty one
SELECT d.id,d.Remark
FROM dbo.DummyTbl AS d
WHERE d.data.exist('//FindMe/text()')=1
--Find IDs, where there is at least one empty FindMe node
SELECT d.id,d.Remark
FROM dbo.DummyTbl AS d
WHERE d.data.exist('//FindMe[empty(text())]')=1
--Now with a variable name to search for
DECLARE #SearchForName NVARCHAR(100)='FindMe';
SELECT d.id,d.Remark
FROM dbo.DummyTbl AS d
WHERE d.data.exist('//*[local-name()=sql:variable("#SearchForName")]/text()')=1
GO
--Clean up
DROP TABLE dbo.DummyTbl;
I maintain a list of new contacts that is sent from a subsidiary. Each month a list of contacts is sent to me. The list is complete and I only need the last few dozen rows to be added to the contacts list. I need to maintain the redundant lists for records purposes.
I am trying to use a CURSOR to inspect the monthly inbound tables and place them into master list?
You don't required and should not be using CURSOR to do that.
Basically just use NOT EXISTS to check for existing and insert
INSERT INTO master_list (contact_id, contact_name, . . . )
SELECT contact_id, contact_name, . .
FROM source_contact_list s
WHERE NOT EXISTS
(
SELECT *
FROM master_list x
WHERE x.contact_id = s.contact_id
)
In SQL Server, i am inserting multiple records into table using batch update. How do i get back the ID's (unique primary key) which is being created after batch update?
If I insert one record, I can get the last inserted using IDENT(tableName). I am not sure how to get if I do batch update. Please help.
For example, I have student table, with ROLE NO and NAME. ROLE NO is auto incremented by 1, as soon I insert the names into DB using java program. I will add 3 rows at a time using batch update from my java code. In DB, it gets added with ROLE NO 2, 3 and 4. How do I get these newly generated ID in my java program, please help
I tried getting ids using getgeneratedkeys method after I do executebatch. I get exception. Is batch update + get generated keys supported.?
In SQL Server when you do an insert there is an extra option your query; OUTPUT. This will let you capture back the data you inserted into the table - including your id's. You have to insert them into a temporary table; so something like this (with your table/ column names will get you there.
declare #MyNewRoles Table (Name, RoleNo)
insert into tblMyTable
(Name)
Select
Name
Output
inserted.Name, Inserted.RoleNo
into #MyNewRoles
From tblMyTableOfNames
select * from #MyNewRoles
If you don't mind adding a field to your table, you could generate a unique ID for each batch transaction (for example, a random UUID), and store that in the table as well. Then, to find the IDs associated with a given transaction you would just need something like
select my_id from my_table where batch_id = ?
I have sqlite local database. I want to insert only fresh data from remote server to local database.Since there is no time field,it is difficult to insert only new records.How can i acheive this? I require this for my hybrid mobile app. Any helps apperciated..Thanks in advance.
Two tables:
my local db table is
tbl_orders
id name age
1 yyy 30
2 xxx 20
my remote db table is
tbl_orders
id name age
1 yyy 36
2 xxx 20
3 vvv 40
4 zzz 37
In the above the remote table contains additionally two records and also the value in first record(age column) get changed.now i want to insert and update this(i.e 1st,3rd,4th) to my local sqlite table without deleting and reinserting the whole table.
You should add a UNIQUE constrain in id.
Redefining your local table:
CREATE TABLE tbl_orders(UNIQUE id, name, age);
or without redefining table
CREATE UNIQUE INDEX tbl_orders_id ON tbl_orders(id);
With constrain, your updates become a single statement:
INSERT OR REPLACE INTO local.tbl_orders SELECT * FROM remote.tbl_orders;
Your table is replicated in two DB?
If yes, you can do an INSERT with NOT EXISTS clause in WHERE condition. Alternatively, add datetime field in your source table.
Another way:
Add a boolean field in your source DB (fl_sent), populated by a trigger when create a new row in your DB or update them. Default value is false, and when you want to syncronize your DBs your select is based on this field
SELECT * FROM myTable WHERE fl_sent = 0
For a more complete answer please post your tables.
EDIT AFTER COMMENT:
Solution 1:
Add field date in your remote table (source) (if you want, you write a trigger about toggle this field) and then execute your sendable query based on this date.
Solution 2:
Add field flag (fl_sent) set by zero (if you want, you write a trigger about toggle this field) and then execute your sendable query based on this flag.
I need to create am index in SQL however it needs to display the records by entering only a part of the name. The index should be created to retrieve the student information using part of the student name (i.e. if the name if Johnanesburg; the user can input John)
I used the syntax below but it wont work
create index Student ON Student(SName)
SELECT * FROM Student WHERE StRegNo LIKE A%
go
I think your problem is here: A%
Try wrapping it in apostrophes.
SELECT *
FROM Student
WHERE StRegNo LIKE 'A%'
Also, you may want a GO statement after you create your index.
The index you are creating over SName will not provide as much benefit for the select statement you are running as one created over StRegNo. Assuming that StRegNo is the primary key on the Student table you could try:
CREATE CLUSTERED INDEX IX_Student on Student(StRegNo)
SELECT *
FROM Student
WHERE StRegNo LIKE 'A%'
However it appears that the SQL you have provided is at odds with your question. If you want to search based on student name then you might want the following instead.
CREATE NONCLUSTERED INDEX IX_Student on Student(SName)
SELECT *
FROM Student
WHERE SName LIKE 'A%'
Ardman got it right regarding your query %A => '%A'. Now as for the index, that's another story that no index can help you with at the time, neither can full text search. If you want to look for names starting with #A (i.e. John%), an ordered index could help but otherwise (i.e. %bur%), you will go for a full table scan !