Search Results

Search found 37012 results on 1481 pages for 'sql query'.

Page 84/1481 | < Previous Page | 80 81 82 83 84 85 86 87 88 89 90 91  | Next Page >

  • LINQ aggregate left join on SQL CE

    - by P Daddy
    What I need is such a simple, easy query, it blows me away how much work I've done just trying to do it in LINQ. In T-SQL, it would be: SELECT I.InvoiceID, I.CustomerID, I.Amount AS AmountInvoiced, I.Date AS InvoiceDate, ISNULL(SUM(P.Amount), 0) AS AmountPaid, I.Amount - ISNULL(SUM(P.Amount), 0) AS AmountDue FROM Invoices I LEFT JOIN Payments P ON I.InvoiceID = P.InvoiceID WHERE I.Date between @start and @end GROUP BY I.InvoiceID, I.CustomerID, I.Amount, I.Date ORDER BY AmountDue DESC The best equivalent LINQ expression I've come up with, took me much longer to do: var invoices = ( from I in Invoices where I.Date >= start && I.Date <= end join P in Payments on I.InvoiceID equals P.InvoiceID into payments select new{ I.InvoiceID, I.CustomerID, AmountInvoiced = I.Amount, InvoiceDate = I.Date, AmountPaid = ((decimal?)payments.Select(P=>P.Amount).Sum()).GetValueOrDefault(), AmountDue = I.Amount - ((decimal?)payments.Select(P=>P.Amount).Sum()).GetValueOrDefault() } ).OrderByDescending(row=>row.AmountDue); This gets an equivalent result set when run against SQL Server. Using a SQL CE database, however, changes things. The T-SQL stays almost the same. I only have to change ISNULL to COALESCE. Using the same LINQ expression, however, results in an error: There was an error parsing the query. [ Token line number = 4, Token line offset = 9,Token in error = SELECT ] So we look at the generated SQL code: SELECT [t3].[InvoiceID], [t3].[CustomerID], [t3].[Amount] AS [AmountInvoiced], [t3].[Date] AS [InvoiceDate], [t3].[value] AS [AmountPaid], [t3].[value2] AS [AmountDue] FROM ( SELECT [t0].[InvoiceID], [t0].[CustomerID], [t0].[Amount], [t0].[Date], COALESCE(( SELECT SUM([t1].[Amount]) FROM [Payments] AS [t1] WHERE [t0].[InvoiceID] = [t1].[InvoiceID] ),0) AS [value], [t0].[Amount] - (COALESCE(( SELECT SUM([t2].[Amount]) FROM [Payments] AS [t2] WHERE [t0].[InvoiceID] = [t2].[InvoiceID] ),0)) AS [value2] FROM [Invoices] AS [t0] ) AS [t3] WHERE ([t3].[Date] >= @p0) AND ([t3].[Date] <= @p1) ORDER BY [t3].[value2] DESC Ugh! Okay, so it's ugly and inefficient when run against SQL Server, but we're not supposed to care, since it's supposed to be quicker to write, and the performance difference shouldn't be that large. But it just doesn't work against SQL CE, which apparently doesn't support subqueries within the SELECT list. In fact, I've tried several different left join queries in LINQ, and they all seem to have the same problem. Even: from I in Invoices join P in Payments on I.InvoiceID equals P.InvoiceID into payments select new{I, payments} generates: SELECT [t0].[InvoiceID], [t0].[CustomerID], [t0].[Amount], [t0].[Date], [t1].[InvoiceID] AS [InvoiceID2], [t1].[Amount] AS [Amount2], [t1].[Date] AS [Date2], ( SELECT COUNT(*) FROM [Payments] AS [t2] WHERE [t0].[InvoiceID] = [t2].[InvoiceID] ) AS [value] FROM [Invoices] AS [t0] LEFT OUTER JOIN [Payments] AS [t1] ON [t0].[InvoiceID] = [t1].[InvoiceID] ORDER BY [t0].[InvoiceID] which also results in the error: There was an error parsing the query. [ Token line number = 2, Token line offset = 5,Token in error = SELECT ] So how can I do a simple left join on a SQL CE database using LINQ? Am I wasting my time?

    Read the article

  • same table, 1 field to 2 field query

    - by edib
    I have 2 tables: 1st holds employees (of ones in any position) and the 2nd holds manager employee relations with id numbers. I want to write a query like 1st field: name(employee), 2nd field: name(manager) How can I do that?

    Read the article

  • How to create Query syntax for multiple DataTable for implementing IN operator of Sql Server

    - by Shantanu Gupta
    I have fetched 3-4 tables by executing my stored procedure. Now they resides on my dataset. I have to maintain this dataset for multiple forms and I am not doing any DML operation on this dataset. Now this dataset contains 4 tables out of which i have to fetch some records to display data. Data stored in tables are in form of one to many relationship. i.e. In case of transactions. N records per record. Then these N records are further mapped to M records of 3rd table. Table 1 MAP_ID GUEST_ID DEPARTMENT_ID PARENT_ID PREFERENCE_ID -------------------- -------------------- -------------------- -------------------- -------------------- 19 61 1 1 5 14 61 1 5 15 15 61 2 4 10 18 61 2 13 23 17 61 2 20 26 16 61 40 40 41 20 62 1 5 14 21 62 1 5 15 22 62 1 6 16 24 62 2 3 4 23 62 2 4 9 27 62 2 13 23 25 62 2 20 24 26 62 2 20 25 28 63 1 1 5 29 63 1 1 8 34 63 1 5 15 30 63 2 4 10 33 63 2 4 11 31 63 2 13 23 32 63 40 40 41 35 65 1 NULL 1 36 65 1 NULL 1 38 68 2 13 22 37 68 2 20 25 39 68 2 23 27 40 92 1 NULL 1 Table 2 Department_ID Department_Name Parent_Id Parent_Name -------------------- ----------------------- --------------- ---------------------------------------------------------------------------------- 1 Food 1, 5, 6 Food, North Indian, South Indian 2 Lodging 3, 4, 13, 20, 23 Room, Floor, Non Air Conditioned, With Balcony, Without Balcony 40 New 40 SubNew TABLE 3 Parent_Id Parent_Name Preference_ID Preference_Name -------------------- ----------------------------------------------- ----------------------- ------------------- NULL NULL NULL NULL 1 Food 5, 8 North Indian, Italian 3 Room 4 Floor 4 Floor 9, 10, 11 First, Second, Third 5 North Indian 14, 15 X, Y 6 South Indian 16 Dosa 13 Non Air Conditioned 22, 23 With Balcony, Without Balcony 20 With Balcony 24, 25, 26 Mountain View, Ocean View, Garden View 23 Without Balcony 27 Mountain View 40 New 41 SubNew I have these 3 tables that are related in some fashion like this. Table 1 will be the master for these 2 tables i.e. table 2 and table 3. I need to query on them as SELECT Department_Id, Department_Name, Parent_Name FROM Table2 WHERE Department_Id in ( SELECT Department_Id FROM Table1 WHERE guest_id=65 ) SELECT Parent_Id, Parent_Name, Preference_Name FROM Table3 WHERE PARENT_ID in ( SELECT parent_id FROM Table1 WHERE guest_id=65 ) Now I need to use these queries on DataTables. So I am using Query Syntax for this and reached up to this point. var dept_list= from dept in DtMapGuestDepartment.AsEnumerable() where dept.Field<long>("PK_GUEST_ID")==long.Parse(63) select dept; This should give me the list of all departments that has guest id =63 Now I want to select all departments_name and parent_name from Table 2 where guest_id=63 i.e. departments that i fetched above. This same case will be followed for Table3. Please suggest how to do this. Thanks for keeping up patience for reading my question.

    Read the article

  • MySQL query to view vertical data

    - by wenkhairu
    I have MySQL data that looks like this: +----------------------------------------+ |Name | kode | jum | +----------------------------------------+ | aman |kode1 | 2 | | aman |kode2 | 1 | | jhon |kode1 | 4 | | amir |kode2 | 4 | +--------------------+-----------+-------+ How can I make the table look like this one, using a MySQL query? kode1 kode2 count aman 2 1 3 jhon 0 4 4 amir 0 4 4

    Read the article

  • Sql query to get the GrandFather name by doing a self join

    - by mahesh
    Hello all , Can any one please give me the query to get the child name and his grand fathers name For eg - if i have a table Relationships in the i have childid and fatherid columns so how will i get the grandfather, i can easily get the father name by using a join but for grandfather i need to do joins 2 times so can any one help me with this D.Mahesh

    Read the article

  • Retrieve data using Dynamic Query and Linq to SQL

    - by GigaPr
    Hi I have a really complicated dynamic query that i want to use to retrieve data from the database I am working in .net 3.5 sql server 2008 i created a stored procedure that accepts a varchar(max) as input parameter and does execute (@SqlQuery) it executes but does not return anything I really would like to use LINQ as all my project is implemented using linq Any Idea how to do it what is the problem?

    Read the article

  • mysql query for getting all messages that belong to user's contacts

    - by aharon
    So I have a database that is setup sort of like this (simplified, and in terms of the tables, all are InnoDBs): Users: contains based user authentication information (uid, username, encrypted password, et cetera) Contacts: contains two rows per relationship that exists between users as (uid1, uid2), (uid2, uid1) to allow for a good 1:1 relationship (must be mutual) between users Messages: has messages that consist of a blob, owner-id, message-id (auto_increment) So my question is, what's the best MySQL query to get all messages that belong to all the contacts of a specific user? Is there an efficient way to do this?

    Read the article

  • set difference in SQL query

    - by TheObserver
    I'm trying to select records with a statement SELECT * FROM A WHERE LEFT(B, 5) IN (SELECT * FROM (SELECT LEFT(A.B,5), COUNT(DISTINCT A.C) c_count FROM A GROUP BY LEFT(B,5) ) p1 WHERE p1.c_count = 1 ) AND C IN (SELECT * FROM (SELECT A.C , COUNT(DISTINCT LEFT(A.B,5)) b_count FROM A GROUP BY C ) p2 WHERE p2.b_count = 1) which takes a long time to run ~15 sec. Is there a better way of writing this SQL?

    Read the article

  • how to use the order by and aggregate function together in sql query

    - by Ranjana
    SELECT count(distinct req.requirementid), req.requirementid, org.organizationid,req. locationofposting,org.registereddate FROM OrganizationRegisteredDetails AS org, RequirementsDetailsforOrganization AS req WHERE org.organizationid =req.requirementid order by org.RegisteredDate desc this shows me the error : Column 'RequirementsDetailsforOrganization.RequirementID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. how to do the 'order by org.RegisteredDate desc' in this Query ....

    Read the article

  • SQL query through an intermediate table

    - by Bryan
    Given the following tables: Recipes | id | name | 1 | 'chocolate cream pie' | 2 | 'banana cream pie' | 3 | 'chocolate banana surprise' Ingredients | id | name | 1 | 'banana' | 2 | 'cream' | 3 | 'chocolate' RecipeIngredients | recipe_id | ingredient_id | 1 | 2 | 1 | 3 | 2 | 1 | 2 | 2 | 3 | 1 | 3 | 3 How do I construct a SQL query to find recipes where ingredients.name = 'chocolate' and ingredients.name = 'cream'?

    Read the article

  • Does ASP.net Report Viewer / Reports require Reporting Services on SQL server

    - by soldieraman
    I have an application that makes use of Report Viewer and Report (.rdlc) files. Does this mean that I need to have "Reporting Services" installed on my SQL server?? Also would not having "SQL Server Analysis services" affect me any way I want to make sure I keep using - SQL Server Profiler - SQL Server Agent - create and run management tasks - Reporting services if the first question's answer is true.

    Read the article

  • SQL query for active users

    - by user344513
    This SQL query gives me today's number of users active in the last 30 days: SELECT COUNT(*) FROM table.users WHERE creation_tsz >= (now() - interval '30 days') How can I modify it to get not a single value, but a table of active users for a range of dates? Thanks, Rob

    Read the article

  • Converting a certain SQL query into relational algebra

    - by Fumler
    Just doing an assignment for my database course and I just want to double check that I've correctly wrapped my head around relational algebra. The SQL query: SELECT dato, SUM(pris*antall) AS total FROM produkt, ordre WHERE ordre.varenr = produkt.varenr GROUP BY dato HAVING total >= 10000 The relational algebra: stotal >= 10000( ?R(dato, total)( sordre.varenr = produkt.varenr( datoISUM(pris*antall(produkt x ordre)))) Is this the correct way of doing it?

    Read the article

  • SQL Query to get Count within a Stored Proc

    - by sia
    So i need to figure out how i can get a record count value and use that count as a new value to insert into a table. Ex: In My Stored Procedure @Count int What im looking for @Count to equal "select top (1) _fieldName from _someTable order by _fieldName Desc" Finally insert into _newTable (_fieldName) values (@Count) End I dont have to use a variable, just trying to demonstrate what im really trying to do. My SQL knowledge is pretty limited so no laughing, or smirking! ;)

    Read the article

  • Optimize "not in" query

    - by Vasu
    Please help optimize this query: SELECT ts.SiteId, COUNT(ts.SiteId) AS Count FROM ts WHERE ts.SiteId not in (SELECT ts.SiteId FROM ts WHERE ts.uniqueid = 'xxx') GROUP BY ts.SiteId ORDER BY Count DESC

    Read the article

  • Sql-server Database query help

    - by menacheb
    Hi, I have a project in C# with a Sql-server Database. In that database I have a table named 'Process' and columns named 'process_name', 'Full_Name' and 'Version' (all of the type:nvarchar(50)). I want to write a query wich will add the new process, only if it doesn't exist in the table yet. How can I do that? Many thanks,

    Read the article

  • Non-SQL API for SQL Server?

    - by David Lively
    Is there any sort of non-SQL API for talking to SQL Server? I'm curious if there is a more direct way to retrieve table or view data. (I don't have a problem with SQL, just curious if any of the layer between the SQL parser and the underlying data store is exposed.)

    Read the article

  • need an sql query

    - by CKeven
    I currently have two tables: 1. car(plate_number, brand, cid) 2. borrow(StartDate, endDate, brand, id) I want to write a query to get all available brand and count of available cars for each brand

    Read the article

  • Connecting to a fresh SQL Server installation

    - by ripper234
    I know mysql, and I'd like to learn sqlserver. I'm currently stuck on the basics of basics: How to install and configure sql server How to connect to it I installed Sql Server through Web Platform Installer, and have Visual Studio 2008 installed. Still, I can't understand how to connect to my server: I see that the SQL service itself (SQLEXPRESS) is running in both in services.msc and Sql Server Configuration Manager I try to connect to it via the Management Studio, but I don't understand what to do. Where do I begin?

    Read the article

  • need help to solve the sql error.

    - by hina
    i want to send SMS using SQL server 2008 express, and using the video tutorial for help. i found an error while testing, i.e. ERROR: Microsoft SQL native client: communication link failure. kindly tell me how to resolve this error. i used the SQL command: "sqlcmd -S np:\127.0.0.1\pipe\MSSQL$SQLEXPRESS\sql\qurey"

    Read the article

  • SQL concatenate rows query

    - by bobobobo
    Say we have a table table posts +---------+-----------+--------------------------------+ | postId | title | status | bodyText | +---------+-----------+--------------------------------+ | 1 | Hello! | deleted | A deleted post! | | 2 | Hello 2! | deleted | Another one! | Can we, in SQL, retrieve a concatenation of a field across rows, by issuing a single query, not having to do the join up in a loop in our back-end code? Something like select title from posts group by status ; Should give "Hello!, Hello 2!"

    Read the article

  • how to optimize this query?

    - by jest
    hi! the query is: select employee_id, last_name, salary, round((salary+(salary*0.15)), 0) as NewSalary, (round((salary+(salary*0.15)), 0) - salary) as “IncreaseAmount” from employees; can i optimize this round((salary+(salary*0.15)), 0) part in anyway, so that it doesn't appear twice..i tried giving it an alias but didn't work :(

    Read the article

  • SQL query, select from 2 tables random

    - by klaus
    Hello all i have a problem that i just CANT get to work like i what it.. i want to show news and reviews (2 tables) and i want to have random output and not the same output here is my query i really hope some one can explain me what i do wrong SELECT anmeldelser.billed_sti , anmeldelser.overskrift , anmeldelser.indhold , anmeldelser.id , anmeldelser.godkendt FROM anmeldelser LIMIT 0,6 UNION ALL SELECT nyheder.id , nyheder.billed_sti , nyheder.overskrift , nyheder.indhold , nyheder.godkendt FROM nyheder ORDER BY rand() LIMIT 0,6

    Read the article

< Previous Page | 80 81 82 83 84 85 86 87 88 89 90 91  | Next Page >