Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Data base :sql server 2008



Step 1:I have a table called "excel" in sql database having columns like cname,firstname,Lastname,etc. I need to fetch all the data from "excel" table using fetch cursor.

Step 2: Once i fetch the data then i need to compare cname with comp_name column with Company table.
if company_name Exist fetch the id for that company else insert the company name as new data

Step 3:once company name exist ,once i fetched the id then with that id i have to compare firstname in person table. if person exists get the id else insert firstname in to person table as new data.

Step 4:if company name exists ,firstname exists get the id and check if lastname exists or not
if exists get id else insert lastname.

Objective is to write stored procedure ,Firstly i have to check the comp_name if exists get id ,with that id i have to check the firstname in person table if exists again get id and check for lname.

Posted
Updated 5-Mar-14 18:23pm
v4
Comments
dan!sh 5-Mar-14 0:03am    
Can you please update your question to include details about "if exists check for next column else insert values for column" statement?
Member 10017719 5-Mar-14 0:04am    
U can use While loop in sql server
King Fisher 5-Mar-14 8:09am    
its not clear man.Do you want to check wheather the id exists or Not?
Thomas Nielsen - getCore 5-Mar-14 13:12pm    
should your procedure do an insert and in case it exists, update intead?
Maciej Los 30-Mar-14 14:46pm    
What have you done till now? Where are you stuck?
Share your code - use "Improve question" widget.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900