if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[temp_Table]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[temp_Table]
GO
CREATE TABLE [dbo].[temp_Table] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[productname] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
insert into temp_table select column from table
declare @i int,@c int,@string varchar(5000),@j varchar(5000)
DECLARE @SQLString NVARCHAR(5000)
select @SQLString=N'select @c = count(*) from temp_table'
execute sp_executesql @sqlstring,
N'@c int output',
@c=@c output
set @i=1
set @string=''
while @i<=@c
begin
s ......
网站更换空间的时候,经常会因为MSSQL数据库名不同,导致从旧空间备份的数据库在新空间还原后无法正常使用。这时候,我们可以通过将数据库表的所有者修改为"dbo"来解决这个问题,具体的方法如下:
打开"Microsoft SQL Server"的“企业管理器”,点开要修改的数据库,选择工具栏上的“工具”-“SQL 查询分析器”,输入以下代码:
1、批量修改MSSQL表的所有者
exec sp_MSforeachtable 'exec sp_changeobjectowner "?","dbo"'
2、单个修改MSSQL表的所有者:
exec sp_changeobjectowner '要改的表名','dbo'
然后按"F5"执行命令,即可修改成功,刷新数据库就可以看到结果了。 ......
-- 任意进制转换为10进制
-- 例 0FA 转换为 16进制 select dbo.f_BinaryToInt('0123456789ABCDEF', '0FA')
CREATE function dbo.f_BinaryToInt(@BinaryFormate varchar(100), @num varchar(200))
--@BinaryFormate 为自定义的进制格式
--@num 为要转换成10进制的自定义进制数
--16进制格式 0123456789ABCDEF
returns DECIMAL(18, 0)
as
BEGIN
declare @result DECIMAL(18, 0), @Binary int, @V char(1), @len int, @value int
SELECT @result=0, @Binary = LEN(@BinaryFormate), @len = 0
SET @num = rtrim(ltrim(upper(reverse(@num)))) --为方便计算,将字符串反向
WHILE @len < LEN(@Num)
BEGIN
SET @V = SUBSTRING(@num, @len + 1, 1)
SET @value = CHARINDEX(@v, @BinaryFormate) -1
SET @result = @value*power(@Binary, @len) + @result
SET @len = @len + 1
END
&n ......
在select語句里面可以使用case來對某個colmun的值進行分別處理,比如
select case color
when 1 then 'red'
when 2 then 'green'
when 3 then 'blue'
else 'black'
end as 'colorName',
foodName from foods
如果使用了left join的時候,某個column的null值需要給一個default value的話,也可以如下:
select foodName, case
when foodPrice is null then 0
else foodPrice
end as price,
foodCost from foods left join foodPrices on foods.foodId = foodPrices.foodId
或者
when nullif(foodPrice, null) is null then 0 ......
create PROCEDURE zdy_CBFY (@SFSS VARCHAR(1),@DWBH varchar(20),@KMBH VARCHAR(10),@KJND VARCHAR(4))
AS
DECLARE @ZWkmye varchar(20),@zwkmzd varchar(20),@ZWSSKMYE varchar(20)
set @zwkmye='zwkmye'+@kjnd
SET @ZWKMZD='ZWKMZD'+@KJND
SET @ZWSSKMYE='ZWSSKMYE'+@KJND
其他程序语言
GO
AS 存储过程语法的一部分,AS之前是存储过程参数和属性定义,AS后面表示存储过程内容的定义。
GO 不是 Transact-SQL 语句;它是可由 sqlcmd 和 osql 实用工具以及 SQL Server Management Studio 代码编辑器识别的命令。
SQL Server 实用工具将 GO 解释为应该向 SQL Server 实例发送当前批 Transact-SQL 语句的信号。当前批语句由上一 GO 命令后输入的所有语句组成,如果是第一条 GO 命令,则由即席会话或脚本开始后输入的所有语句组成。
GO 命令和 Transact-SQL 语句不能在同一行中。但在 GO 命令行中可包含注释。
SELECT * into erp_tticst001502 from OPENQUERY(ERP,'select t$sitm,t$pdno from baan.tticst001502 where substr(t$pdno,1,4)=''A907''')
insert into erp_tticst001502 select * from OPENQUERY(ERP,'se ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID=diamond;Password=88888888;Initial Catalog=EmailAnalyse" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace OfficeOutlook
{
/// <summary>
///DataBase 的摘要说明
/// </summary>
public class DataBase
{
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
&n ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID=diamond;Password=88888888;Initial Catalog=EmailAnalyse" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace OfficeOutlook
{
/// <summary>
///DataBase 的摘要说明
/// </summary>
public class DataBase
{
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
&n ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID=diamond;Password=88888888;Initial Catalog=EmailAnalyse" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace OfficeOutlook
{
/// <summary>
///DataBase 的摘要说明
/// </summary>
public class DataBase
{
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
&n ......