Rails Group by inside Group by

I need to group my ActiveRecords first by YEAR and then by MONTH, something like this: {2017=> "January"=> [Record1, record2, etc] "February"=> [Record1, record2, etc] 2016=> "January"=> [Record1, record2, etc]

How to convert this SQL statement to linq in C #?

Please help me to convert this SQL statement to Linq in C#: string cmd = "SELECT * FROM dbo.Personnel WHERE (dbo.Personnel.FName LIKE @FName + '%' AND dbo.Personnel.LName LIKE @LName +'%')"; if (objPPersonnel.PersonnelCode != 0) { cmd += "A

Have two id user tables and the link between them

I have the first table 'users' | id | name ------------------ | 1 | james | 2 | johnny | 3 | Carl | 4 | Lea And my second table contain the linked users linked_users | id | linked_id -------------------- | 1 | 2 | 1 | 4 | 2 | 3 I need to get two fiel

select sections that have no student enrolled

I want to select all sections which do not have any students enrolled These are the three tables: ENROLLMENTS student_id, section_id SECTIONS course_id, section_id COURSES course_id, description The output table should look like this: course_id | des

SQL inserting twice

Hello i have a sql statement that ranks my records and inserts the ranks into a database. The problem i am having is that when i run the script. It deletes the old rankings. And inserts the new rankings fine, but it inserts every ranking twice. So th

SQL 'while' to read data from a table in a variable

How could I write a while loop to populate data from a table to a variable to be used in a seperate query ? EX: select ITEM from Table1 ITEM A0001 B0001 C0003 D0005 E0032 If I can get all that results here under column ITEM to @var1 and then use it i

Oracle Timestamp to DateTime SQL Server

I have multiple statements from oracle database and I need to use them in SQL Server insert into COMENZI (NR_COMANDA, DATA, MODALITATE, ID_CLIENT, STARE_COMANDA, ID_ANGAJAT) values (2456, to_timestamp('08-11-1998 07:53:25.989889', 'dd-mm-yyyy hh24:mi

Paging problem when sorting based on the last modified property

I need to show some records sorted based on modified column (latest activity on top) (Post with new edit or comments at the top) App UI has twitter like 'more' post button for infinite scroll. each 'more' will add next 10 records to UI. Issue is that

SQL query to select one of the multiple rows of a table

I have a table which contains more than one row for a particular value . Here is the table structure: NAME,NUMBER,STATUS,DESC,START_DATE,END_DATE A,3,X,DetailsOfX,13-10-15,13-10-15 A,2,Y,DetailsOfY,13-10-15,13-10-15 A,2,Z,DetailsOfZ,13-10-15,13-10-15

Insert SQL for multiple records

I get the error message when I run the following query in MSSQL Server 2005. Error Message is Incorrect syntax near ','. I think query is ok. But I don't know why I get error. INSERT INTO PERSON (ID, EMP_NAME) VALUES ('E001', 'AAA'), ('E002', 'BBB');

Interview the last event each person attended

I have a table called CampRegistration with the following structure: [EID] INT, [CampName] VARCHAR(100), [StartDt] DATETIME EID is the identifier of the person who attended the camp. I wish to select the last camp each person in the CampRegistration

Identity insertion on the linked server fails

I want to use a stored procedure to copy a table from my test database to a linked server with the same ID's / Identity but I can't get it to work.. I've set the IDENTITY_INSERT to ON but it still complains about the ID column. Here's my procedure: C

Quick way to write the SQL server table into the file

I have a remote SQL server. I want to make a local copy of all tables in this server. I don't care about the file format used locally, I'm looking for the fastest approach of getting the data from SQL server into the file. (note: server side backup i

Casting Error - Changed Channels to Time

In my application I have a datagrid that populates with info from a SQLserver DB. Amongst other things the data which populates the grid includes times. Now I struggled for some time getting the data from the DB to look the way I wanted. In the end m

Get SQL Agent Service Service Account Details

How can I get the Service Account name for the SQL Agent service for a particular SQL Server (SQL 2005). Is it possible to get using SQL statements or WMI ?You can use the sc.exe. To find SQL instances services: sc \\<remote computer name> query | f

Alternative for the union in SQL where-clause

in where clause i am using like SELECT name FROM products WHERE id IN ( SELECT product_id FROM orders UNION SELECT 1); it taking time to perform union. please provide some other alternative to improve my query performancewhat about select name from p

MySQL Street Address Blurred Search

Does anyone know of a good script (or good strategy) for doing a fuzzy street address search on a MySQL database? The key issues are: capitalization (easy -- just use LCASE) punctuation (could use REPLACE; not sure it there are more efficient options

Return a record of a subquery in a result set

I am attempting to return a rowcount from a subquery as part of a result set. Here is a sample that I've tried that didn't work: SELECT recordID , GroupIdentifier , count() AS total , (SELECT COUNT() FROM table WHERE intActingAsBoolean = 1) AS Approv

Cursor in the While Loop

My Cursor and Output SET NOCOUNT ON DECLARE @vendor_id int, @vendor_name nvarchar(50) DECLARE @subvendor_id int, @subvendor_name nvarchar(50) PRINT '-------- Vendor Products Report --------' DECLARE vend_cursor CURSOR FOR SELECT * FROM MYSEQ OPEN ven