從key抓前7碼丟回去dataf,欄位去更新完SUBSTRING(dataf,18,7),條件是原本SUBSTRING(dataf,18,7)='0000000'+上另一個條件,
--UPDATE modre
--SET dataf=SUBSTRING(dataf,1,17)+SUBSTRING(key,1,7)+SUBSTRING(key,1,7)+SUBSTRING(dataf,32,datalength(dataf)-31)
--WHERE key>='1070701000101'
--and key < '1070801000101'
--AND SUBSTRING(data,1,5)='01038'
--and SUBSTRING(dataf,18,7)='0000000'
===================================================
計算ip次數,ip > 10 ,再排序
SELECT ip, COUNT(IP) as new_count_ip
FROM [dbo].[123RegLog]
GROUP BY ip
HAVING COUNT(IP) > 10
order by new_count_ip desc;
計算ip次數,ip > 10,ip <> '',指定日期
SELECT IP,COUNT(IP) as new_count_ip
FROM [dbo].[123RLog]
where ldate >= '2015-05-28'
GROUP BY ip
HAVING COUNT(IP) > 10
AND ip <> ''
計算ip次數,同一個ip下不同ID出現幾次,再排序,這個在sql express版的跑要花不少時間
SELECT IP,COUNT(IP) AS IP_COUNT,COUNT(DISTINCT IDNO) AS COUNT_IDNO
FROM [RLog]
where IP <> ''
GROUP BY[IP]
order by IP_COUNT DESC
IP | IP_COUNT | IDNO_COUNT |
192.168.XX.54 | 114 | 6 |
192.168.XX.82 | 92 | 6 |
192.168.XX.72 | 86 | 32 |
61.XX.XX.66 | 83 | 69 |
60.XX.XX.14 | 79 | 77 |
SELECT [123Date]
,[123RegDate]
,[123IDNO]
,CASE [LogType]
WHEN 'A' THEN '初診掛號'
WHEN 'B' THEN '複診掛號'
WHEN 'C' THEN '取消掛號'
WHEN 'D' THEN '查詢掛號'
WHEN 'E' THEN '查詢看診進度'
END AS [NWLogType]
,[IP]
FROM [dbo].[123RegLog]
where IP IS NOT NULL
UPDATE "表格名" SET "欄位1" = [新值] WHERE "條件";
驗證過可用1030723,要修改 [user] 這資料表裡的 [user].status 欄位
新值是 0 ,但條件要 JOIN 其他資料表 user_in_role 這資料有才放帳號的角色資料
user_in_role.role_id 放有帳號角色
UPDATE [user] set [user].status = '0'
FROM [user] INNER JOIN
user_in_role ON [user].user_id = user_in_role.user_id
WHERE (user_in_role.role_id = '3') and (user_in_role.user_id = '1113')
西元轉民國
第一種
select convert(varchar(3),CONVERT(int,year(getdate())-1911))+right(CONVERT(char(8),getdate(),2),6) as qday
第二種
SELECT CONVERT(VARCHAR(4),CONVERT(VARCHAR(4),GETDATE(),20) - 1911) + '/' +
SUBSTRING(CONVERT(VARCHAR(10),GETDATE(),20),6,2) + '/' +
SUBSTRING(CONVERT(VARCHAR(10),GETDATE(),20),9,2)
第三種
SELECT
CAST((CAST(DATEPART(YEAR,GETDATE()) AS NUMERIC(4))-1911) AS VARCHAR(3))
+ REPLACE(CONVERT(CHAR(5), GETDATE(), 1),'/','')
沒有留言:
張貼留言