查询Table name, Column name, 拼接执行sql文本, 游标, 存储过程, 临时表
018_Proc_UpdateTranslations.sql:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO if (exists (select * from sys.objects where name = 'UpdateTranslationsForTable'))
drop proc [UpdateTranslationsForTable]
go CREATE PROCEDURE [dbo].[UpdateTranslationsForTable]
(
@tableName NVARCHAR(128)
)
AS
BEGIN
-- ---
SET NOCOUNT ON
-- ---
-- ---
DECLARE @translationTableName NVARCHAR(128)
DECLARE @sql NVARCHAR(4000) -- ---
SET @tableName = REPLACE(@tableName, '''', '''''') -- injection protection
IF @tableName = '_dynamicText'
BEGIN
SET @translationTableName = @tableName
END
ELSE
BEGIN
SET @translationTableName = @tableName + 'Translation'
END -- ---------------------------------------------------------------------------
-- --- Build strings of columns that we will insert into / select from
-- --- Certain columns are NOT to be translated and those are listed here.
-- ---
-- ---------------------------------------------------------------------------
DECLARE @colTbl TABLE (rowId INT NOT NULL IDENTITY(1,1), columnName NVARCHAR(128), maxLen INT NULL, appendQ TINYINT NOT NULL, PRIMARY KEY (rowId))
-- ---
INSERT INTO @colTbl (columnName, maxLen, appendQ)
SELECT column_name, character_maximum_length,
CASE WHEN data_type = 'nvarchar' AND (character_maximum_length >= 100 OR character_maximum_length = -1)
AND column_name NOT IN ('OwnerUserId', 'UserName', 'UserId', 'OwnerUserId', 'AssessingUserName',
'CompletedById', 'TargetAttractionRationale', 'ResourceFileName', 'ResourceURL')
THEN 1 ELSE 0 END -- this case value indicates to only append ?xx- to certain columns, not these ones listed
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = @translationTableName
AND column_name NOT IN ('Language', 'Id', 'tVersion','IsSynchronized')
ORDER BY ordinal_position
-- ---
DECLARE @update NVARCHAR(4000)
DECLARE @colName NVARCHAR(128)
DECLARE @conditions NVARCHAR(128)
DECLARE @appendQ TINYINT
DECLARE @colLen NVARCHAR(20) -- for nvarchar columns, this is the column size number converted to nvarchar
DECLARE @minRow INT
DECLARE @maxRow INT
SELECT @minRow = MIN(rowId), @maxRow = MAX(rowId) FROM @colTbl
WHILE (@minRow <= @maxRow)
BEGIN
SELECT @colName = columnName, @appendQ = appendQ, @colLen = CAST(CASE WHEN maxLen = -1 THEN 4000 ELSE maxLen END AS VARCHAR) FROM @colTbl WHERE rowId = @minRow SET @update = ISNULL(@update + ', ', '') + '[' + @colName + ']='+ CASE WHEN @appendQ = 1 THEN 'SUBSTRING([' + @colName + '], 5, ' + @colLen + ')' ELSE @colName END
SET @conditions = ISNULL(@conditions + 'and ', '') + '[' + @colName + '] like ''?en-%'' ' SET @minRow = @minRow + 1
END
-- ---------------------------------------------------------------------------
-- --- update certain languages in the translation table
------------------------------------------------------------------------------ SET @sql = N'UPDATE ' + @translationTableName + ' SET '+@update+' where language like ''en-%'' and '+@conditions EXEC sp_executesql @statement = @sql END
019_Cur_UpdateTranslations.sql :
-- ===================================================================================
-- === Script to update translations for specified languages to be the same as xx-XX in all translations tables
-- ===================================================================================
DECLARE @sql NVARCHAR(4000),@tableName NVARCHAR(128)
-- ===
PRINT '--============ Starting Update for All Translations ============--'
-- ===================================================================================
-- === create a cursor for each sql table that holds translated data
-- ===================================================================================
DECLARE tableCursor CURSOR FOR
-- Select all tables that follow the 'standard' translations system
SELECT T.name
FROM sys.tables T
WHERE EXISTS (SELECT NULL FROM sys.tables TT WHERE TT.name = T.name + 'Translation')
AND T.name NOT IN ('Permission')
-- Add any tables that follow the 'standard' translations system
UNION SELECT '_dynamicText' OPEN tableCursor
FETCH tableCursor INTO @tableName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ''
PRINT '------ Updating Translations For ' + @tableName + ' ------' EXEC UpdateTranslationsForTable @tableName PRINT '------ Update Translations For ' + @tableName + ' Done ------' FETCH tableCursor INTO @tableName
END
CLOSE tableCursor
DEALLOCATE tableCursor
PRINT '--============ Finished Updating All Translations ============--'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO if (exists (select * from sys.objects where name = 'UpdateTranslationsForTable'))
drop proc [UpdateTranslationsForTable]
go CREATE PROCEDURE [dbo].[UpdateTranslationsForTable]
(
@tableName NVARCHAR(128)
)
AS
BEGIN
-- ---
SET NOCOUNT ON
-- ---
-- ---
DECLARE @translationTableName NVARCHAR(128)
DECLARE @sql NVARCHAR(4000) -- ---
SET @tableName = REPLACE(@tableName, '''', '''''') -- injection protection
IF @tableName = '_dynamicText'
BEGIN
SET @translationTableName = @tableName
END
ELSE
BEGIN
SET @translationTableName = @tableName + 'Translation'
END -- ---------------------------------------------------------------------------
-- --- Build strings of columns that we will insert into / select from
-- --- Certain columns are NOT to be translated and those are listed here.
-- ---
-- ---------------------------------------------------------------------------
DECLARE @colTbl TABLE (rowId INT NOT NULL IDENTITY(1,1), columnName NVARCHAR(128), maxLen INT NULL, appendQ TINYINT NOT NULL, PRIMARY KEY (rowId))
-- ---
INSERT INTO @colTbl (columnName, maxLen, appendQ)
SELECT column_name, character_maximum_length,
CASE WHEN data_type = 'nvarchar' AND (character_maximum_length >= 100 OR character_maximum_length = -1)
AND column_name NOT IN ('OwnerUserId', 'UserName', 'UserId', 'OwnerUserId', 'AssessingUserName',
'CompletedById', 'TargetAttractionRationale', 'ResourceFileName', 'ResourceURL')
THEN 1 ELSE 0 END -- this case value indicates to only append ?xx- to certain columns, not these ones listed
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = @translationTableName
AND column_name NOT IN ('Language', 'Id', 'tVersion','IsSynchronized')
ORDER BY ordinal_position
-- ---
DECLARE @update NVARCHAR(4000)
DECLARE @colName NVARCHAR(128)
DECLARE @conditions NVARCHAR(128)
DECLARE @appendQ TINYINT
DECLARE @colLen NVARCHAR(20) -- for nvarchar columns, this is the column size number converted to nvarchar
DECLARE @minRow INT
DECLARE @maxRow INT
SELECT @minRow = MIN(rowId), @maxRow = MAX(rowId) FROM @colTbl
WHILE (@minRow <= @maxRow)
BEGIN
SELECT @colName = columnName, @appendQ = appendQ, @colLen = CAST(CASE WHEN maxLen = -1 THEN 4000 ELSE maxLen END AS VARCHAR) FROM @colTbl WHERE rowId = @minRow SET @update = ISNULL(@update + ', ', '') + '[' + @colName + ']='+ CASE WHEN @appendQ = 1 THEN 'SUBSTRING([' + @colName + '], 5, ' + @colLen + ')' ELSE @colName END
SET @conditions = ISNULL(@conditions + 'and ', '') + '[' + @colName + '] like ''?en-%'' ' SET @minRow = @minRow + 1
END
-- ---------------------------------------------------------------------------
-- --- update certain languages in the translation table
------------------------------------------------------------------------------ SET @sql = N'UPDATE ' + @translationTableName + ' SET '+@update+' where language like ''en-%'' and '+@conditions EXEC sp_executesql @statement = @sql END
查询Table name, Column name, 拼接执行sql文本, 游标, 存储过程, 临时表的更多相关文章
- Entity Framework Core 执行SQL语句和存储过程
无论ORM有多么强大,总会出现一些特殊的情况,它无法满足我们的要求.在这篇文章中,我们介绍几种执行SQL的方法. 表结构 在具体内容开始之前,我们先简单说明一下要使用的表结构. public clas ...
- EF Core 执行SQL语句和存储过程
无论ORM有多么强大,总会出现一些特殊的情况,它无法满足我们的要求.在这篇文章中,我们介绍几种执行SQL的方法. 表结构 在具体内容开始之前,我们先简单说明一下要使用的表结构. public clas ...
- Oracle学习2 视图 索引 sql编程 游标 存储过程 存储函数 触发器
---视图 ---视图的概念:视图就是提供一个查询的窗口,来操作数据库中的数据,不存储数据,数据在表中. ---一个由查询语句定义的虚拟表. ---查询语句创建表 create table emp a ...
- 如何用VS EF连接 Mysql,以及执行SQL语句 和存储过程?
VS2013, MySQL5.7.18 , MySQL5.7.14 执行SQL语句: ztp_user z = new ztp_user(); object[] obj = new object[] ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(89)-EF执行SQL语句与存储过程
这一节,我们来看看EF如何执行SQL语句与读取存储过程的数据,可能有一部分人,还不知道EF如何执行存储过程与原生SQL语句! 我们什么时候要直接使用原生的SQL语句? 返回值过于复杂 过于复杂的联合查 ...
- SQL内部拼接执行SQL语句时,实现变量参数化
exec sp_ExecuteSql执行的SQL语句拼接起是比较麻烦,如果关联的表多拼接过程是很容易出错的,下面这方法非常的好用,而且简单直观 if exists(select * from syso ...
- 测试JdbcTemplate执行SQL语句和存储过程
我在项目中需要使用到oracle的语句片段和存储过程.下面就是我的测试案例: public class DbTest extends BaseTestCase { @Resource JdbcUtil ...
- sql循环-游标、临时表、表变量
游标 在游标逐行处理过程中,当需要处理的记录数较大,而且游标处理位于数据库事务内时,速度非常慢. -- 声明变量 DECLARE @Id AS Int -- 声明游标 DECLARE C_Id CUR ...
- Java下拼接执行动态SQL语句(转)
在实际业务中经常需要拼接动态SQL来完成复杂数据计算,网上各类技术论坛都有讨论,比如下面这些问题: http://bbs.csdn.net/topics/390876591 http://bbs.cs ...
随机推荐
- ARC工程中添加非ARC文件
转载自:http://blog.csdn.net/zhenweicao/article/details/16988543 分类: IOS2013-11-27 17:02 626人阅读 评论(0) 收藏 ...
- OO之观察者模式
以下为观察者模式详解: 引子: 假设有这样一个问题,有一条河经过一个山谷,山谷下有一个村庄,人们在山谷处修建了一个水库,并安排专人管理,当水库的水位过高时要通知下游居民注意水库的开闸放水,当水库的水温 ...
- 轻仿QQ音乐之音频歌词播放、锁屏歌词-b
先上效果图 歌词播放界面 音乐播放界面 锁屏歌词界面 一. 项目概述 前面内容实在是太基础..只想看知识点的同学可以直接跳到第三部分的干货 项目播放的mp3文件及lrc文件均来自QQ音乐 本文主要主要 ...
- 友盟分享在appdelegate中的调用语句举例
//友盟 [UMSocialData setAppKey:UmengAppkey]; [UMSocialConfig setSupportedInterfaceOrientations:UIInter ...
- DX 的.x 文件
template Header { <3D82AB43-62DA-11cf-AB39-0020AF71E433> WORD major; WORD minor; DWORD flags;} ...
- vc2008程序发布指南
vc2008程序发布指南 2008-05-03 17:46 vc2008开发的程序的发布方式可以有5种方式: 1. 采用静态链接到crt和MFC. 只要你拥有组成程序的所有源代码,你就可以采用这种方式 ...
- POJ2524+并查集
题意简单. 询问n个人的宗教关系. #include<stdio.h> ; int fa[ maxn ]; int vis[ maxn ]; void init( int n ){ ;i& ...
- C++对象的自销毁
记得在学校里的时候,曾经这样写过: void MyClass::KillMe() { delete this; } 老师看到这句话的时候,眼珠子都快瞪出来了.但是运行正确啊,没什么问题. 现在想起来, ...
- Delphi函数翻译成VC要注意句柄指针传递(传递Handle的时候,必须加上一个指针引用,才能消除编译错误)
Delphi里做了魔法变化,每个变量名称本身就是指针,因为不怎么需要指针语法.我也不知道是不是因为这个原因引起的Delphi与VC对句柄的不同处理. 这是Delphi的强行关机函数,好用,调用方式:W ...
- 113. Path Sum II
题目: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the give ...