sql - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. More than 1 value was returned. -


iam trying query , these following errors. error saying primary key constraint pk_itempath has been violated. should inorder rectify error query wont able run

use sk_en_userdb go  set noexec off  go if(db_name() not '%_userdb') begin     raiserror ('you must run script in userdb database',18,0)     set noexec on end  go  if(not exists(select * userrights.path pathid = 'myviews')) begin     insert userrights.path(pathid, isvendorspecific)     values('myviews', 0) end   if(not exists(select * userrights.products projectname = 'products')) begin     insert userrights.products(productid, projectname)     values(         (select max(productid) + 1 [userrights].products),         'products'     ) end  insert userrights.productstopath(productid, pathid) values(     (select productid     [userrights].products     projectname = 'products'),     'myviews' )  insert userrights.modulestoproducts(moduleid, productid) values(     (select moduleid     [userrights].[modules]     displayname = 'products product' or hierarchyname '%products product%'),      (select productid     [userrights].products     projectname = 'products') ) 

first, inner selects returning more 1 value per insert statement.

try changing insert statements from:

insert userrights.productstopath(productid, pathid) values(     (select productid     [userrights].products     projectname = 'products'),     'myviews' ) 

to:

insert userrights.productstopath(productid, pathid) (select top 1 productid     [userrights].products     projectname = 'products'),     'myviews' 

if need batch inserts (more 1 record per statement), use cursor.

with regards itempath pk violation - question doesn't give me enough information table schema, error means you're inserting record primary key exists. inner selects well.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -