zoukankan      html  css  js  c++  java
  • sql2008 join语句另一种用法,减少运行速度

    CREATE PROCEDURE [dbo].[sp_get_user_configs]
    @system_id int,
    @config_table_version int,
    @specified_uids nvarchar(max)
    AS
    BEGIN

    if(@system_id < 1)
    return
    if(@config_table_version =0)
    set @config_table_version = null

    -- 取得 system_type
    declare @system_type int
    select @system_type=system_type from t_system where system_id = @system_id

    ;with _x as (
    SELECT user_id
    ,[config_item_id]
    ,[config_item_value]
    ,[config_deadline]
    ,[config_item_title]
    ,[config_item_name]
    ,[config_item_type]
    ,[config_table_id]
    ,[system_type]
    ,[config_table_version]
    ,0 as [type]
    ,'用户私有' as [type_name]
    ,config_item_parent_id
    FROM [v_user_config]
    right join (select item from f_str_split(@specified_uids)) as b
    on b.item = user_id
    where system_type=@system_type and config_table_version=ISNULL(@config_table_version,config_table_version)
    union all
    SELECT [user_id]
    ,[config_item_id]
    ,[config_item_value]
    ,[config_deadline]
    ,[config_item_title]
    ,[config_item_name]
    ,[config_item_type]
    ,[config_table_id]
    ,[system_type]
    ,[config_table_version]
    ,[role_id] as [type]
    ,[role_name] as [type_name]
    ,config_item_parent_id
    FROM [v_role_config]
    right join (select item from f_str_split(@specified_uids)) as c
    on c.item = user_id
    where system_type=@system_type and config_table_version=ISNULL(@config_table_version,config_table_version)
    )
    select
    [user_id],
    [config_item_id],
    [type],
    [type_name],
    [config_item_title],
    [config_item_name],
    [config_item_value],
    [config_item_type],
    [config_deadline],
    [config_table_id],
    [system_type],
    [config_table_version],
    config_item_parent_id
    from _x
    order by user_id desc

    END

  • 相关阅读:
    一个Electron的设计缺陷及应对方案
    如何点击穿透Electron不规则窗体的透明区域
    Electron团队为什么要干掉remote模块
    Clickhouse 单机双实例
    Kafka安全认证SASL/PLAIN
    Syslog的使用
    Kafka Consumer
    Kafka Producer客户端
    Kafka客户端操作
    springboot集成flyway实践
  • 原文地址:https://www.cnblogs.com/babyfacer/p/2547829.html
Copyright © 2011-2022 走看看