how to write query to get today’s date data in SQL server ? select * from tbl_name where date =
SQL – Convert String to Date and compare – Conversion failed when converting datetime from character string
I currently have dates stored in a general attribute field in the database as a string. They are all stored in the format DD/MM/YYYY for example 01/01/2000 I am able to convert them them to datetime …
Using Inner join and sorting records in descending order
I am working with two tables(student_class and class) in my database. I have a query below that shows class that have students. But it is not quite what I am looking for. How to display classes that have students but show the results so maximum seats is descending. Would count be needed? Tables: Student_class…
Seperate first and last names from single column
I have a person table where the name column contains names, some in the format “first last” and some in the format “first”. My query SELECT name, SUBSTRING(name FROM 1 FOR POSITION(‘ ‘ IN name) ) AS …
PostgreSQL distinct rows joined with a count of distinct values in one column
I’m using PostgreSQL 9.4, and I have a table with 13 million rows and with data roughly as follows: There are indices on md5(a), on b, and on (md5(a), b). (In reality, a may contain values longer than 4k chars.) There is also a primary key column of type SERIAL which I have omitted above. I’m tryi…
SQL not recognizing column alias in where clause
I am only a beginner in SQL, but I’ve come across this annoying error. SQL is having an issue with the WHERE clause of this script: SELECT ITEM_ID, ITEM_PRICE, DISCOUNT_AMOUNT, QUANTITY, (…
JPA @Column annotation to create comment/description
I was wondering is it possible to create from jpa/hibernate annotation a database column description/comment like this: ALTER TABLE tablename CHANGE status status INT(11) NOT NULL COMMENT ‘sample description/comment’; It will be great functionality, but I cant find anything about this in JPA speci…
How to count the number of rows with a date from a certain year in CodeIgniter?
I have the following query. $query = $this->db->query(‘SELECT COUNT(*) FROM iplog.persons WHERE begin_date LIKE ‘2014%”); I need to count the number of columns with a begin_date in the year …
SET CONSTRAINTS ALL DEFERRED not working as expected
In a PostgreSQL 9.3 database, if I define tables a and b as follows: And then do the following: It produces the error below. Why is SET CONSTRAINTS not having the desired effect? Answer Only DEFERRABLE constraints can be deferred. Let me suggest superior alternatives first: 1. INSERT in order Reverse the sequ…
TRIM function on SQL Server 2014
IN SQLite I wrote : UPDATE MYTABLE SET MYFIELD = TRIM(MYFIELD); What to do to have this on SQL Server 2014 ?