Click here to Skip to main content
11,409,532 members (50,049 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
Hi Frnds,
I have three tables with city,State,Country.In one Stored Procedure i need to insert,update ,select three table values.For that i need nested if Stored Procedure Flow.
for eg.: i am passing all my values from C# pages to stored procedure...
id,name,type(city,state,country),process(insert,select,update)
if i pass value as City.First i need to check whether that city name is already exist or not.after that if not exist i need to save,other wise i need to pass value to C# page as "Already Exist"...Same thing have to be do for State,Country
Posted 3-Dec-12 4:27am
Comments
ShailendraPatel at 3-Dec-12 10:51am
   
how many columns in your table id and name or more what's the purpose of city,state,country if is cascading then use separate table for city,state and country

or

you have to store in this table your client info then also create three table and make cascading relationship between them and store id of city,state,country in user table
itsureshuk at 4-Dec-12 0:06am
   
i have three tables(city state country)...I need one stored procedure ,if i am going to insert city details, i have to check, whether same city name is already exist, if not exist have to insert,otherwise if exist have to return a value 10 or anything...so that i can show message as already exist in User form

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

HI,

Tou can try like this.

 
IF EXISTS(select * from city where Name = 'abc')
{
     return "already exists";
}
ELSE
{
    IF(status = "update")
    { //write your update code here...}
    ELSE IF(status = "insert")
    {  //Write your insert query here...}
    ELSE
    { //select query...}
 
}

Thanks
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,731
1 OriginalGriff 6,895
2 Maciej Los 3,332
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100