Is it possible to use where clause with insert statement. In my scenario im not getting how to use update query as the subquery returns more than one values.
My query goes like this.
INSERT EntityAttributeValue
(
EntityID
)
SELECT ID
FROM (SELECT ID
FROM (SELECT ID,
ROW_NUMBER() over(ORDER BY ID) Row
FROM Item
)
x
WHERE Row BETWEEN 1 AND 400
)
x
WHERE Value='10KT Gold'
What i want here to do is, I have EntityID and Value column in EntityAttributeValue table and the Other table is Item table which contains ID’s. So joining goes this way Item.ID = EntityAttributeValue.EntityID. Now, i want to Insert bulk ItemID values from Item table into EntityAttributeValue table where values = ’10KT Gold’ .
Please let me know.
There are couple of problems
You use
xtwo times as table names. Even if it works, it will confuse anyone. Use a new name every time.Add the table name before the column name to make clear what comes from where.
Where does
valuecome from? It’s not in the result set of any query that you execute.[EDIT] This query should work:
but the result is probably not what you want because it will only select items which are already in
EntityAttributeValue.