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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 complicated procedure

Author  Topic 

logpop
Starting Member

16 Posts

Posted - 2013-07-30 : 18:09:52
Can someone help me write this sql procedure:
for each product in productsTable:
if productName is in this format: name1|property1| (ie one | character at end of name, other somewhere before)
and product with name1 doesn't exist in table:
insert new product into productTable which is copy of this product, only name has name1 (without |property|).

thanks for help :)

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-07-30 : 18:24:20
You will get a quicker response if you post your question following these guidelines:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-31 : 01:31:34
translating your explanation directly to t-sql would be something like this

INSERT ProductsTable (ProductName)
SELECT LEFT(ProductName,CHARINDEX('|',ProductName)-1)
FROM productsTable
WHERE LEN(productName) - LEN(productName,'|','')=2
AND productName LIKE '%|%|'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -