sqlserver.snippets 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # ISNULL
  2. snippet isnull
  3. ISNULL(${1:check_expression}, ${2:replacement_value})
  4. # FORMAT
  5. snippet format
  6. FORMAT(${1:value}, ${2:format})
  7. # CAST
  8. snippet cast
  9. CAST(${1:expression} AS ${2:data_type})
  10. # CONVERT
  11. snippet convert
  12. CONVERT(${1:data_type}, ${2:expression})
  13. # DATEPART
  14. snippet datepart
  15. DATEPART(${1:datepart}, ${2:date})
  16. # DATEDIFF
  17. snippet datediff
  18. DATEDIFF(${1:datepart}, ${2:startdate}, ${3:enddate})
  19. # DATEADD
  20. snippet dateadd
  21. DATEADD(${1:datepart}, ${2:number}, ${3:date})
  22. # DATEFROMPARTS
  23. snippet datefromparts
  24. DATEFROMPARTS(${1:year}, ${2:month}, ${3:day})
  25. # OBJECT_DEFINITION
  26. snippet objectdef
  27. SELECT OBJECT_DEFINITION(OBJECT_ID('${1:sys.server_permissions /*object name*/}'))
  28. # STUFF XML
  29. snippet stuffxml
  30. STUFF((SELECT ', ' + ${1:ColumnName}
  31. FROM ${2:TableName}
  32. WHERE ${3:WhereClause}
  33. FOR XML PATH('')), 1, 1, '') AS ${4:Alias}
  34. ${5:/*https://msdn.microsoft.com/en-us/library/ms188043.aspx*/}
  35. # Create Procedure
  36. snippet createproc
  37. -- =============================================
  38. -- Author: ${1:Author}
  39. -- Create date: ${2:Date}
  40. -- Description: ${3:Description}
  41. -- =============================================
  42. CREATE PROCEDURE ${4:Procedure_Name}
  43. ${5:/*Add the parameters for the stored procedure here*/}
  44. AS
  45. BEGIN
  46. -- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
  47. SET NOCOUNT ON;
  48. ${6:/*Add the T-SQL statements to compute the return value here*/}
  49. END
  50. GO
  51. # Create Scalar Function
  52. snippet createfn
  53. -- =============================================
  54. -- Author: ${1:Author}
  55. -- Create date: ${2:Date}
  56. -- Description: ${3:Description}
  57. -- =============================================
  58. CREATE FUNCTION ${4:Scalar_Function_Name}
  59. -- Add the parameters for the function here
  60. RETURNS ${5:Function_Data_Type}
  61. AS
  62. BEGIN
  63. DECLARE @Result ${5:Function_Data_Type}
  64. ${6:/*Add the T-SQL statements to compute the return value here*/}
  65. END
  66. GO