求一存储过程写法!谢谢!
我有三张表,分别是客户表,联系人表和机会表,机会表中有opporunity_custid字段和客户表主键相关联
我想查询客户信息以及联系人信息和机会表中是否有相应客户的机会信息,有记录就显示 '有 '反之则显示 "无 "
表结构如下:
CREATE TABLE [dbo].[t_Opporunity] (
[Opporunity_ID] [int] IDENTITY (1, 1) NOT NULL ,
[Opporunity_CustID] [int] NULL ,
[Opporunity_LinkMan] [int] NULL ,
[Opporunity_Content] [nvarchar] (800) COLLATE Chinese_PRC_CI_AS NULL ,
[Opporunity_Create] [int] NULL ,
[Opporunity_Club] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Opporunity_DelFlag] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[t_LinkMan] (
[LinkMan_ID] [int] IDENTITY (1, 1) NOT NULL ,
[Customer_ID] [int] NULL ,
[LinkMan_Name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_Sex] [bit] NULL ,
[LinkMan_Mobile] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_Phone] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_Fax] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_Email] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[MSN] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_Dept] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_Duty] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[LinkMan_CreateTime] [datetime] NULL ,
[LinkMan_Role] [int] NULL ,
[LinkMan_DelFlag] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[t_Customer] (
[Customer_ID] [int] IDENTITY (1, 1) NOT NULL ,
[Customer_Name] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Cuatomer_Industry] [int] NULL ,
[Customer_CuLe] [int] NULL ,
[Customer_PostAddress] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[Customer_PostCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Customer_Web] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[Customer_Phone] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Customer_Manager] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Customer_Product] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Prod_Remark] [nvarchar] (2000) COLLATE Chinese_PRC_CI_AS NULL ,
[Customer_Date] [datetime] NULL ,
[Customer_DelFlag] [int] NULL
) ON [PRIMARY]
GO
求高手帮帮忙,谢谢!
[解决办法]
Select
A.*,
B.*,
(Case When Opporunity_ID Is Not Null Then N '有 ' Else '无 ' End) As Flag
From
t_Customer A
Inner Join
t_LinkMan B
On A.Customer_ID = B.Customer_ID
Left Join
t_Opporunity C
On A.Customer_ID = C.Opporunity_CustID