Conversion failed when converting date and/or time from character string while inserting datetime

I was trying to create a table as follows, create table table1(date1 datetime,date2 datetime); First I tried inserting values as below, insert into table1 values(’21-02-2012 6:10:00 PM’,’01-01-2001 12:00:00 AM’); It has given error saying, Cannot convert varchar to datetime Then I tried below format as one of the post suggested by our stackoverflow, insert into … Read more

How to insert multiple rows from a single query using eloquent/fluent

I have the following query: $query = UserSubject::where(‘user_id’, Auth::id())->select(‘subject_id’)->get(); and as expected I get the following result: [{“user_id”:8,”subject_id”:9},{“user_id”:8,”subject_id”:2}] Is there a way of copying the above result into another table so that my table looks like this? ID|user_id|subject_id 1 |8 |9 2 |8 |2 The problem I have is that the $query can expect any … Read more

What is the purpose of Order By 1 in SQL select statement?

I’m reading through some old code at work, and have noticed that there are several views with an order by 1 clause. What does this accomplish? Example: Create view v_payment_summary AS SELECT A.PAYMENT_DATE, (SELECT SUM(paymentamount) FROM payment B WHERE PAYMENT_DATE = B.PAYMENT_DATE and SOME CONDITION) AS SUM_X, (SELECT SUM(paymentamount) FROM payment B WHERE PAYMENT_DATE = … Read more