Getting only Month and Year from SQL DATE

As well as the suggestions given already, there is one other possiblity I can infer from your question: – You still want the result to be a date – But you want to ‘discard’ the Days, Hours, etc – Leaving a year/month only date field SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, <dateField>), 0) AS [year_month_date_field] FROM <your_table> … Read more

Escaping keyword-like column names in Postgres

Simply enclose year in double quotes to stop it being interpreted as a keyword: INSERT INTO table (id, name, “year”) VALUES ( … ); From the documentation: There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes (“). A delimited … Read more

How to retrieve the current value of an oracle sequence without increment it?

SELECT last_number FROM all_sequences WHERE sequence_owner=”<sequence owner>” AND sequence_name=”<sequence_name>”; You can get a variety of sequence metadata from user_sequences, all_sequences and dba_sequences. These views work across sessions. EDIT: If the sequence is in your default schema then: SELECT last_number FROM user_sequences WHERE sequence_name=”<sequence_name>”; If you want all the metadata then: SELECT * FROM user_sequences WHERE … Read more

Oracle “(+)” Operator

That’s Oracle specific notation for an OUTER JOIN, because the ANSI-89 format (using a comma in the FROM clause to separate table references) didn’t standardize OUTER joins. The query would be re-written in ANSI-92 syntax as: SELECT … FROM a LEFT JOIN b ON b.id = a.id This link is pretty good at explaining the … Read more

How to find current transaction level?

Run this: SELECT CASE transaction_isolation_level WHEN 0 THEN ‘Unspecified’ WHEN 1 THEN ‘ReadUncommitted’ WHEN 2 THEN ‘ReadCommitted’ WHEN 3 THEN ‘Repeatable’ WHEN 4 THEN ‘Serializable’ WHEN 5 THEN ‘Snapshot’ END AS TRANSACTION_ISOLATION_LEVEL FROM sys.dm_exec_sessions where session_id = @@SPID learn.microsoft.com reference for the constant values.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)