存储过程嵌套如果否则 [英] Stored Procedure Nested If else

查看:120
本文介绍了存储过程嵌套如果否则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Frnds,

我有三个表,包含city,State,Country。在一个存储过程中,我需要插入,更新,选择三个表值。因为我需要嵌套,如果存储过程流程。

例如:我将所有值从C#页面传递给存储过程...

id,name,type(city,state,country),process (插入,选择,更新)

如果我将值传递给City.First我需要检查该城市名称是否已经存在。之后如果不存在我需要保存,其他明智的我需要将值传递给C#页面为已经存在...同样的事情必须为州,国家

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

推荐答案

HI,



Tou可以尝试这样。





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


这篇关于存储过程嵌套如果否则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆