SQL Server
SQL Server Common SQLServer charindex ( string_expression1 , string_expression2 [ , start_location ]  ) ค้นหา "string_expression2" สำหรับ "string_expression1" แรกที่ปรากฏและส่งคืนจำนวนเต็ม "Start_location" เป็นตำแหน่งอักขระที่เริ่มต้นหา "string_expression1" ใน "string_expression2" ถ้าไม่ได้ระบุ "start_location" จะเป็นตัวเลขลบ หรือเป็นศูนย์ การค้นหาจะเริ่มต้นที่ตำแหน่งเริ่มต้นของ "string_expression2" concat ( string_expression1 , string_expression2 ) ส่งคืนสตริงที่เป็นผลลัพธ์ของการรวม "string_expression1" กับ "string_expression2" ตัวอย่าง: concat ( [Sales (query)].[Sales staff].[First name], [Sales (query)].[Sales staff].[Last name] ) ผลลัพธ์: ส่งคืนชื่อและนามสกุล เช่น Bob Smith {current_user} { current_user } ส่งคืนชื่อของผู้ใช้ปัจจุบัน datalength ( string_expression ) ส่งคืนความยาวเป็นไบต์ของ "string_expression" dateadd ( { datepart } , integer_expression , date_expression ) ส่งคืนวันที่ที่เป็นผลลัพธ์จากการเพิ่ม "integer_expression" หน่วย (ที่ระบุโดย "datepart" (day, month, year)) เข้ากับ "date_expression" datediff ( {datepart} , date_expression1 , date_expression2 ) ส่งคืนจำนวนของ "datepart" (day, month, year) หน่วยระหว่าง "date_expression1" และ "date_expression2" ตัวอย่าง: datediff ( {yy} , 1984-01-01 , 1997-01-01 ) ผลลัพธ์: 13 datename ( ' { ' datepart ' } ' , date_expression ) ส่งคืน "datepart" จาก "date_expression" ที่สามารถเป็นค่า datetime, smalldatetime, วันที่หรือเวลาเช่นเดียวกับสตริง ASCII โปรดสังเกตว่า "datepart" ต้องเป็นคีย์เวิร์ดที่แทน datepart หรือเป็นตัวย่อที่ Microsoft® SQL Server รู้จักและต้องอยู่ในวงเล็บปีกกา ตัวอย่าง: datename ( {mm} , 2000-01-01 ) ผลลัพธ์: January datepart ( ' { ' datepart ' } ' , date_expression ) ส่งคืนส่วนของ "date_expression" (เช่น เดือน) เป็นจำนวนเต็ม "date_expression" สามารถเป็นค่า datetime, smalldatetime, วันที่หรือเวลา โปรดสังเกตว่า "datepart" ต้องเป็นคีย์เวิร์ดที่แทน datepart หรือเป็นตัวย่อที่ Microsoft® SQL Server รู้จักและต้องอยู่ในวงเล็บปีกกา ตัวอย่าง: datepart ( {wk} , 2000-01-01 ) ผลลัพธ์: 1 (สัปดาห์แรกของปี) day ( date_expression ) ส่งคืนส่วนของวันของ "date_expression" เช่นเดียวกับการแตก (วันจาก date_expression) difference ( string_expression1 , string_expression2 ) ส่งคืนค่าจำนวนเต็มที่แทนความแตกต่างระหว่างค่าที่ส่งคืนโดยฟังก์ชัน data source-specific soundex สำหรับ "string_expression1" และ "string_expression2" ค่าที่ส่งคืนมีช่วงจาก 0 ถึง 4 ที่ 4 หมายถึงตรงกันที่สุด โปรดสังเกตว่า 4 ไม่ได้หมายถึงสตริงเท่ากัน ตัวอย่าง: difference ([Sales target (query)].[Sales Staff].[First name],[Sales (query)].[Retailers].[Contact first name]) ผลลัพธ์: 0 ตัวอย่าง: difference ([Sales target (query)].[Sales Staff].[First name],[Sales target (query)].[Sales Staff].[First name]) ผลลัพธ์: 4 getdate () ส่งคืนค่าวันที่เวลาที่แทนวันที่และเวลาปัจจุบันของคอมพิวเตอร์ที่รันซอฟต์แวร์ฐานข้อมูล isnull ( expression , expression ) ส่งคืนอาร์กิวเมนต์แรกที่ไม่ใช่ null (หรือ null ถ้าอาร์กิวเมนต์ทั้งสองเป็น null) แนะนำให้ใช้ฟังก์ชัน COALESCE มาตรฐาน sql แทน ตัวอย่าง: isnull ( [Sales (query)].[Sales Fact].[Sales quantity] , 0 ) ผลลัพธ์: ส่งคืนปริมาณของยอดขาย ถ้าไม่เป็น null ไม่เช่นนั้นจะส่งคืน 0 left ( string_expression , integer_expression ) ส่งคืน "integer_expression" อักขระที่อยู่ซ้ายสุดของ "string_expression" ตัวอย่าง: left ( [Sales (query)].[Sales staff].[Last name] , 3 ) ผลลัพธ์: ส่งคืนอักขระสามตัวแรกของแต่ละนามสกุล ltrim ( string_expression ) ส่งคืน "string_expression" ที่ลบช่องว่างที่นำหน้า month ( date_expression ) ส่งคืนส่วนของเดือนของ "date_expression" เช่นเดียวกับการแตก (เดือนจาก date_expression) patindex ( string_expression1 , string_expression2 ) ส่งคืนจำนวนเต็มที่แทนตำแหน่งเริ่มต้นของ "string_expression1" แรกที่ปรากฏใน "string_expression2" ส่งคืน 0 ถ้าไม่พบ "string_expression1" อักขระไวด์การ์ด % ต้องนำหน้าและต่อจาก "string_expression1" ยกเว้นเมื่อค้นหาอักขระแรกและอักขระสุดท้าย ตัวอย่าง: patindex ( '%po%', 'Report' ) ผลลัพธ์: 3 replace ( string_expression1 , string_expression2 , string_expression3 ) แทนที่ "string_expression2" ทั้งหมดที่ปรากฏใน "string_expression1" ด้วย "string_expression3" replicate ( string_expression , integer_expression ) ส่งคืนสตริงที่ประกอบด้วย "string_expression" ซ้ำ "integer_expression" ครั้ง reverse ( string_expression ) ส่งคืน "string_expression" ในลำดับที่กลับกัน rtrim ( string_expression ) ส่งคืน "string_expression" ที่ตัดช่องว่างที่ต่อท้ายออก ตัวอย่าง: rtrim ( [Sales (query)].[Sales staff].[Last name] ) ผลลัพธ์: ส่งคืนนามสกุลที่ลบช่องว่างใดๆ ที่อยู่ท้ายชื่อออก sign ( numeric_expression ) ส่งคืนตัวบ่งชี้ของเครื่องมหาย "numeric_expression": +1 ถ้า "numeric_expression" เป็นบวก 0 ถ้าเป็นศูนย์ หรือ -1 ถ้าเป็นลบ space ( integer_expression ) ส่งคืนสตริงที่ประกอบด้วย "integer_expression" ช่องว่าง str ( numeric_expression [ , integer_expression1 [ , integer_expression2 ] ] ) ส่งคืนสตริงที่แทน "numeric_expression" โดยที่ "integer_expression1" เป็นความยาวของสตริงที่ส่งคืนและ "integer_expression2" เป็นจำนวนของหลักทศนิยม stuff ( string_expression1 , integer_expression1 , integer_expression2 , string_expression2 ) ส่งคืนสตริง โดยที่ "integer_expression2" อักขระถูกลบออกจาก "string_expression1" ที่เริ่มต้นที่ "integer_expression1" และโดยที่ "string_expression2" ถูกแทรกลงใน "string_expression1" ที่เริ่มต้น อักขระแรกในสตริงอยู่ที่ตำแหน่ง 1 year ( date_expression ) ส่งคืนตำแหน่งปีของ "date_expression" เช่นเดียวกับการแตก (ปีจาก date_expression) ascii ( string_expression ) ส่งคืนตัวเลขที่แทนค่ารหัส ascii ของอักขระที่อยู่ซ้ายสุดของ "string_expression" ตัวอย่าง: ascii ( 'A' ) ผลลัพธ์: 65 char ( integer_expression ) ส่งคืนอักขระที่มีค่ารหัส ASCII ที่ระบุโดย "integer_expression" "Integer_expression" ควรอยู่ระหว่าง 0 และ 255 ตัวอย่าง: char ( 65 ) ผลลัพธ์: A right ( string_expression , integer_expression ) ส่งคืน "integer_expression" อักขระที่อยู่ขวาสุดของ "string_expression" round ( numeric_expression , integer_expression ) ส่งคืน "numeric_expression" ที่ปัดเศษเป็นค่าที่ใกล้เคียงกับ "integer_expression" ตำแหน่งทางขวาของจุดทศนิยมที่สุด การปัดเศษจะเกิดขึ้นก่อนการใช้การจัดรูปแบบข้อมูล ตัวอย่าง: round (125, -1) ผลลัพธ์: 130 soundex ( string_expression ) ส่งคืนสตริงอักขระสี่ตัวที่แทนเสียงของคำใน "string_expression"
SQL Server Cast cast_float ( expression ) ส่งคืนค่าของ "expression" ที่ cast เป็น float cast_real ( expression ) ส่งคืนค่าของ "expression" ที่ cast เป็นค่า real cast_smallint ( expression ) ส่งคืนค่าของ "expression" ที่ cast เป็น small integer cast_integer ( expression ) ส่งคืนค่าของ "expression" ที่ cast เป็นจำนวนเต็ม ตัวอย่าง: integer ( 84.95 ) ผลลัพธ์: 85 cast_timestamp ( expression ) ส่งคืนค่าของ "expression" cast เป็นวันที่เวลา cast_char ( expression ) ส่งคืนค่าของ "expression" ที่ cast เป็นอักขระ ส่งคืนอักขระไม่เกิน 30 ตัว cast_varchar ( expression ) ส่งคืนค่าของ "expression" ที่ cast เป็นอักขระตัวแปร
SQL Server Math log ( numeric_expression ) ส่งคืนลอการิทึมธรรมชาติของ "numeric_expression" log10 ( numeric_expression ) ส่งคืนลอกาลิทึมฐานสิบของ "numeric_expression" pi () ส่งคืนค่าคงที่ของ pi เป็นค่า floating point rand ( integer_expression ) สร้างเลขสุ่มโดยใช้ "integer_expression" เป็นค่า seed
SQL Server Trigonometry acos ( numeric_expression ) ส่งคืน arccosine ของ "numeric_expression" เป็นเรเดียน arccosine เป็นมุมที่มีค่า cosine เป็น "numeric_expression" asin ( numeric_expression ) ส่งคืน arcsine ของ "numeric_expression" เป็นเรเดียน arcsine เป็นมุมที่มีค่า sine เป็น "numeric_expression" atan ( numeric_expression ) ส่งคืน arctangent ของ "numeric_expression" เป็นเรเดียน arctangent เป็นมุมที่มีค่า tangent เป็น "numeric_expression" atn2 ( numeric_expression1, numeric_expression2 ) ส่งคืน arctangent ของจุดตัด x และ y ที่ระบุโดย "numeric_expression1" และ "numeric_expression2" ตามลำดับ เป็นเรเดียน arctangent เป็นมุมที่มีค่า tangent เป็น "numeric_expression1" cos ( numeric_expression ) ส่งคืน cosine ของ "numeric_expression" โดยที่ "numeric_expression" เป็นมุมที่แสดงเป็นเรเดียน cot ( numeric_expression ) ส่งคืน cotangent ของ "numeric_expression" โดยที่ "numeric_expression" เป็นมุมที่แสดงเป็นเรเดียน degrees ( numeric_expression ) ส่งคืน "numeric_expression" เรเดียนที่แปลงเป็นองศา radians ( numeric_expression ) ส่งคืนตัวเลขของเรเดียนที่แปลงจาก "numeric_expression" องศา sin ( numeric_expression ) ส่งคืน sine ของ "numeric_expression" โดยที่ "numeric_expression" เป็นมุมที่แสดงเป็นเรเดียน tan ( numeric_expression ) ส่งคืน tangent ของ "numeric_expression" โดยที่ "numeric_expression" เป็นมุมที่แสดงเป็นเรเดียน