1樓:匿名使用者
create table #temp
(id int null,
uid int null,
name nvarchar(50) null)
create table #temp1
(id int null,
class nvarchar(50) null,
users nvarchar(50) null)
insert into #temp values(1,1,'a')
insert into #temp values(2,2,'b')
insert into #temp values(3,3,'c')
insert into #temp values(4,4,'d')
insert into #temp values(5,5,'e')
insert into #temp values(6,6,'f')
insert into #temp1 values(1,'class1','1,2,3')
insert into #temp1 values(2,'class2','4,5,6')
--select top 0 * into #tem2 from #temp1
declare @num int
select @num = count(*) from #temp1
print @num
while @num>0
begin
declare @name nvarchar(50)
declare @users nvarchar(50)
set @name = '';
select @users = users from #temp1 where id =@num
print @users
while(charindex(',',@users)<>0)
begin
--第乙個','之前的字串
select @name +=name+',' from #temp where id = convert(int,substring(@users,1,charindex(',',@users)-1))
--將第乙個','後面的字串重新賦給@ids
set @users=stuff(@users,1,charindex(',',@users),'')
--最後乙個字串
if(charindex(',',@users)=0)
begin
select @name +=name from #temp where id = @users
update #temp1 set users = @name where id = @num
--insert into #tem2 select id,class,@name from #temp1 where id = @num
endend
set @num = @num-1
print @name
endselect * from #temp1
--select * from #tem2 order by id
--drop table #tem2
drop table #temp
drop table #temp1
2樓:唐人街
寫個標量函式 做一下轉換
關於sql語句的乙個問題 20
3樓:薔薇夜天涯
將接收到的日期在sql裡面,進行轉換。datepart()datepart(month, '2015-07-07 20:00:00') 得到的是07
datepart(year,'2015-07-07 20:00:00')得到的是2015
atepart(year,'2015-07-07 20:00:00')+'_'+atepart(year,'2015-07-07 20:00:00')
得到的就是2015_07了。其它的,你自己進行字元連線就行了。
關於sql語句的問題
4樓:sql的藝術
select
a.requestid,a.htsjbm,b.departmentmark
from
formtable_main_48 a
left join hrmdepartment b on a.htsjbm=b.id
乙個資料庫sql語句問題
sql語句問題 關於乙個判斷
5樓:冰悅精彩
您好:這種不用太明白。
大概的意思就是如果存在這個procedure。
那麼就drop 掉。
下面應該還有create procedure的語句吧。
乙個sql語句問題
6樓:革曼華劍鳥
假如表中沒有name='小五'的資料,你單從這個表裡面是查詢不到這種結果的
除非你還有另一張表存在name=『小五』的記錄,把兩表關聯查詢就可以得到你的這種結果
7樓:匿名使用者
解釋:to_char用來把日期型,整數型等型別強制轉換成字元型,比如times 欄位為 2009-07-02格式是日期格式的。
用to_char轉換結果為:
select to_char(times,'yyyymm') from dual;
結果:200907
8樓:匿名使用者
你試試這樣可以不:
using system.data;
int sum = 0;
string sql = "select sum(shjdefen) as shj from tb_kaoshilist where shjmbid='" + id + "'";
oledbconnection conn = new oledbconnection(da.databasepath(server));
conn.open();
oledbcommand cmd = new oledbcommand();
cmd.connection = conn;
cmd.commandtype = commandtype.text;
cmd.commandtext = sql;
datatable tb= cmd.executereader();
if (tb,rows.count>0)
9樓:匿名使用者
感覺目標字段型別是number
應該是下面這樣吧:
to_number('200907')
10樓:醫病者父母心
to_char('200907','yyyymm'), 沒有一點意義,完整語句貼上來
關於SQL查詢的問題,乙個關於SQL查詢的問題。
select corpno,sum amt as sumamt from 表 group bycorpno,convert varchar 6 date,112 這個就是能實現你前兩列的顯示。乙個sql中不能按2種方法去彙總。所以total這一列得單獨彙總。然後再把資料聯合查詢一下。select c...
乙個很複雜的SQL語句問題,超級達人請進
很簡單呀 select dpath,pv count 1 ip count distinct dip from tablename group by dpath 測試了,沒問題!以上是sql server的實現。access 這樣 select dpath,select count 1 from t...
關於英語句子寫法的疑問,乙個關於英語句子寫法的疑問
簡單的句子譯成五種,至少有關的英語詞彙,有乙個動詞。所有英語句子離不開這五種基本句型,二手五個句子是 一十個v 主語 謂語 結構,頁2。十大v 10 p 主語 動詞 表語 的結構 三十大v 10 o 主語 謂語 賓語 結構 4 sv ten十十o1,o2 主語 謂語 雙目標 建設 5。所以ten十十...
乙個關於情感的問題,關於情感問題
哈哈,看來你得閉關一段時間才可以,去修煉一些可以闖蕩江湖的武林秘籍,不過要記住,練啥都可以,別練葵花寶典,要是出來闖蕩碰上哥我的話,你會敗在哥手下。人得閱歷是需要經過磨練體會才能悟出其中的道理,沒有捷徑,再好的鋼也要經過千錘百鍊方可練就才。從始到終都要保持人生的正確方向,用真誠的態度去感染你身邊的每...
關於空之軌跡SC的問題,乙個關於空之軌跡SC的問題
紺碧?小怪比前幾個塔少,有3個強力魔獸。小怪其實基本上可以無視,對魔法抗性都差不多,帶誰都能打,如攻擊力和其他人比相差太多則說明物攻或魔攻之類的能力值 由等級和裝備決定 相差太大。塔頂執行者為露茜奧拉,因為露茜奧拉召喚出的2個霧魔比較頭疼,乙個魔免乙個物免,所以帶誰主要還是看你小艾和雪拉準備配成法系...