本區已經依照台灣網站內容分級規定加入分級標籤,
不歡迎也禁止未滿 18 歲的人員進入本區
對多元文化的尊重, 也是對您自己, 以及您工作, 或許也包括對您親人的尊重。
如果您了解, 並可以尊重且遵守以上注意事項, 否則請您關閉並離開此板。
內容可能含有與男性間性行為有關的文字, 如果您無法接受男性間性行為, 或對男性間性行為沒有興趣, 請您選擇「離開

目前分類:new 程式碼_Javascript(SQL) (12)

瀏覽方式: 標題列表 簡短摘要

先建立一個 db_executor 並給予 EXECUTE 權限,再將需要添加的成員加入角色即可。

CREATE ROLE [db_executor]
GO

GRANT EXECUTE TO [db_executor]
GO

文章標籤

倧齊 發表在 痞客邦 留言(0) 人氣()

/*取得日期區間內預設工作日*/
CREATE FUNCTION dbo.PL_getDefaultWorkingDays
(
    @StartDate DATE,
    @EndDate   DATE

文章標籤

倧齊 發表在 痞客邦 留言(0) 人氣()

EOMONTH (Transact-SQL)
以選擇性位移,傳回包含指定日期的當月最後一天。

SQL Server 2012 版本新增加
 

文章標籤

倧齊 發表在 痞客邦 留言(0) 人氣()

-------------------------------------------------------------------------------------------------------------------------------
使用方式
-------------------------------------------------------------------------------------------------------------------------------
/*
PL_setTempTable 'XX'

文章標籤

倧齊 發表在 痞客邦 留言(0) 人氣()

子查詢

子查詢意指巢狀結構存在於SELECT、INSERT、UPDATE、DELETE敘述中的SELECT查詢。子查詢可在巢狀子查詢 ,子查詢為join關聯資料子查詢與無關聯資料使用in(某段SELECT資料來源),在效能表現上關連子查詢會較無 關聯子查詢表現較優。

-- 使用子查詢來檢查是否符合
--關連查詢
SELECT DISTINCT s.PurchaseOrderNumber
FROM Sales.SalesOrderHeader s
WHERE EXISTS ( SELECT SalesOrderID
FROM Sales.SalesOrderDetail
WHERE UnitPrice BETWEEN 1000 AND 2000 AND
SalesOrderID = s.SalesOrderID)

--無關連子查詢
SELECT SalesPersonID,
SalesQuota CurrentSalesQuota
FROM Sales.SalesPerson
WHERE SalesQuota IN
(SELECT MAX(SalesQuota)
FROM Sales.SalesPerson)


查詢多個資料來源(JOIN)

文章標籤

倧齊 發表在 痞客邦 留言(0) 人氣()

If the results table of your stored proc is too complicated to type out the "create table" statement by hand, and you can't use OPENQUERY OR OPENROWSET, you can use sp_help to generate the list of columns and data types for you. Once you have the list of columns, it's just a matter of formatting it to suit your needs.

Step 1: Add "into #temp" to the output query (e.g. "select [...] into #temp from [...]").

The easiest way is to edit the output query in the proc directly. if you can't change the stored proc, you can copy the contents into a new query window and modify the query there.

Step 2: Run sp_help on the temp table. (e.g. "exec tempdb..sp_help #temp")

After creating the temp table, run sp_help on the temp table to get a list of the columns and data types including the size of varchar fields.

倧齊 發表在 痞客邦 留言(6) 人氣()

  • 這篇文章限定好友觀看。
    若您是好友,登入後即可閱讀。
  • 這篇文章限定好友觀看。
    若您是好友,登入後即可閱讀。
  • 這篇文章限定好友觀看。
    若您是好友,登入後即可閱讀。
  • 這篇文章限定好友觀看。
    若您是好友,登入後即可閱讀。
  • 這篇文章限定好友觀看。
    若您是好友,登入後即可閱讀。
  • 這篇文章限定好友觀看。
    若您是好友,登入後即可閱讀。