發表文章

目前顯示的是 8月, 2017的文章

轉置SQL及stored procedure foreach

ALTER PROCEDURE [dbo].[zToNewSalesFeat] AS BEGIN   TRUNCATE TABLE newsalesfeat   --先把要INSERT的TABLE清空 DECLARE @oneid INT DECLARE the_cursor CURSOR FAST_FORWARD FOR select code from MAN_Data where [Date] between '2017/1/1' and '2017/12/31' order by BGCode,[Date] OPEN the_cursor FETCH NEXT FROM the_cursor INTO @oneid WHILE @@FETCH_STATUS = 0 BEGIN INSERT  newSalesFeat select man_code,[201701],[201702],[201703],[201704],[201705],[201706],[201707],[201708],[201709],[201710],[201711],[201712] from ( select man_code,Period,FYA from SS_Feat where Man_Code=@oneid and ct in (1,100) and Period between 201701 and 201712 ) as s pivot ( sum(fya) for period in ([201701],[201702],[201703],[201704],[201705],[201706],[201707],[201708],[201709],[201710],[201711],[201712]) ) as p FETCH NEXT FROM the_cursor INTO @oneid END CLOSE the_cursor DEALLOCATE the_cursor END

SSH、SCP連線LINUX

ssh USERNAME@IP 例:  $ssh root@192.168.1.99 連上線後要求輸入密碼 如果你的ssh port不是開在port 22,而是開在別的port,再加註port  例: $ ssh USERNAME@192.168.1.99 -p SSH_PORT  scp的用法跟cp很像         如果在REMOTE_MACHINE上有一個檔案~/ken.txt,想透過scp下載回來的話         $ scp -P port USERNAME@REMOTE_MACHINE:~/ken.txt ./         接著會要求你輸入密碼(如果有設定成免密碼登入的話就不會要求密碼)         反過來,如果是要上傳ken.txt到REMOTE_MACHINE上的~目錄呢?很簡單,就反過來         $ scp -P SSH_PORT ./ken.txt USERNAME@REMOTE_MACHINE:~/         目錄也可以         $ scp -r -P SSH_PORT ./ken_dir USERNAME@REMOTE_MACHINE:~/ Syntax: (Local to Remote) scp /path/to/local/file.txt user@192.168.10.100:/remote/path/ Syntax: (Remote to Local) scp user@192.168.10.100:/remote/file.txt /path/to/local/