CUNY ACE Upskilling: Introduction to Structured Query Language (SF21JOB) — Day 8

We are reaching the end of the course and this means programmability.

    CREATE PROCEDURE quick_example @in_param VARCHAR(50)
      -- passing a value into the procedure using parameter
      -- `@in_param` declared as a VARCHAR(50)
    AS
      BEGIN
      -- beginning of code do something when executing this 
      -- procedure
        DECLARE @out_param VARCHAR(50)
            -- receive value from it has been processed, using 
            -- the same data type (VARCHAR(50))
        SET @out_param = CONCAT (
            '`',
            @in_param,
            '` processed as `',
            UPPER(@in_param),
            '`'
            )
            -- passing a value. the original value processed
        PRINT @out_param
            -- printing the value of the output parameter
      -- end of code to do something when executing this procedure
      END;

Download the class notes for day 8.

CUNY ACE Upskilling: Introduction to Structured Query Language (SF21JOB) — Day 6

We are half-way done with the course. We are now creating, dropping and altering objects.

    CREATE  obj_type   obj_name [some_code]

    CREATE  DATABASE   db_name;

    CREATE  SCHEMA     schema_name;

    CREATE  TABLE      table_name;
      (
        field_1 datatype_1 [atributes],
        field_2 datatype_2 [atributes],
        field_3 datatype_3 [atributes],
        ...
      );

    CREATE  VIEW       view_table
    AS
      (
        SELECT fields...
        FROM table(s)
      );

Download the class notes for day 6.

CUNY ACE Upskilling: Introduction to Structured Query Language (SF21JOB) — Day 5

We have worked with data coming from one function fed into another. We need to keep in mind that the process starts from the inside out.

    function_5(some_value5...
      function_4(some_value4...
        function_3(some_value3...
          function_2(some_value2...
            function_1(some_value1...
              ) -- output of function_1 into function_2
            ) -- output of function_2 into function_3
          ) -- output of function_3 into function_4
        ) -- output of function_4 into function_5
      ) -- output of function_5

We have seen functions that affect strings and numeric values including `FORMAT()` to change the look of dates and currencies. Doing the latter changes the value from a numeric value to a string by default in SQL Server to `NVARCHAR(n)`.

Download the class notes for day 5.

CUNY ACE Upskilling: Introduction to Structured Query Language (SF21JOB) — Day 2

We are finally playing with data. To request data from a table or group of, we need to follow the following structure for the SELECT statement. Any changes in the syntax will break the statement and return an error.

	SELECT table1.field1,
		table1.field2...
		table2.field1,
		table2.field2...
	FROM table1
	INNER | (OUTER) LEFT | (OUTER) RIGHT table2
		ON table1.common_field1 = table2.common_field1...;

Download the class notes for day 2.