使用SQL語句實現SPLIT效果的幾種方法

2021-04-06 19:37:44 字數 1003 閱讀 6209

create table [table1] (

[id] [int] identity (1, 1) not null ,

[name] [char] (10) collate chinese_prc_ci_as null ,

constraint [pk_table1] primary key  clustered

([id]

)  on [primary]

) on [primary]

go--1

declare @nvchsql nvarchar(500)

declare @nvchnumbers nvarchar(50)

set @nvchnumbers = n'2,4,6'

set @nvchsql = n'select * from table1 where id in (' + @nvchnumbers + n')'

print @nvchsql

--exec sp_executesql @nvchsql

exec(@nvchsql)

--2select * from table1 where id in (2,4,6)

declare @s nvarchar(50)

set @s = n'select * from table1 where id in '+ n'2,4,6'

exec(@s)

--3 第一種方法的另外表示方法 去除n也可以

declare @nvchsql nvarchar(500)

declare @nvchnumbers nvarchar(50)

set @nvchnumbers = '2,4,6'

set @nvchsql = 'select * from table1 where id in (' + @nvchnumbers + ')'

print @nvchsql

--exec sp_executesql @nvchsql

exec(@nvchsql)

sql語句使用

1.需求 按照查詢順序條件的排列順序返回 要點 where.in select from t device where guid in guid1 guid2 order by field guid,guid1 guid2 2.需求 替換資料表中的欄位中相同資料 要點 replace函式 語法 re...

sql語句實現分頁

sql語句實現分頁 sqlstr select top 10 from shebei where id not in select top cint pagenum 1 10 id from shebei order by id desc order by id desc 計算總頁數 dimstr ...

sql 語句實現分頁

select top 每頁顯示的資料量 from 表名 where 主鍵或者其他欄位 select isnull max 主鍵或者其他欄位 0 from select top 每頁顯示的數量量 第幾頁 主鍵或者其他欄位 from 表名 order by 主鍵或者其他欄位 a order by 主鍵或...

SQL語句使用須知

1 說明 複製表 只複製結構,源表名 a 新表名 b access可用 法一 select into b from a where 1 1 僅用於sqlserver 法二 select top 0 into b from a 2 說明 拷貝表 拷貝資料,源表名 a 目標表名 b access可用 i...

使用反射實現生成新增 修改sql語句

1.生成新增sql語句 單獨一個model時 public static string insertsql t t object value pi.getvalue t,null if value null continue 未給值,null value commonfunc.uninjection...