SQL Server Selecting DISTINCT record to string variable

I want to select all distinct name from person table to VARCHAR variable . I have write a query that returns all name as follow. DECLARE @pName as VARCHAR(MAX) SET @pName=” SELECT @pName += RTRIM(FullName) + ‘,’ FROM Persons SELECT @pName When I try to select distinct on FullName, SQL Server throws an exception. DECLARE […]

How to use CASE in the WHERE clause

I have two columns in my table field1 and field2. In my where i want to make a check if field2 IS NULL or not. If NULL then my where would look like this where field1 = ‘myvalue’ If it’s not NULL i want to concatenate the values from field1 and field2 with a + […]

Entity Framework SQL

I hope anyone can help me. How do I build up a query like this in Entity Framework in C#. My SQL query looks like this: select Id, dbo.AccessRight(Id, 5) from Customers where Id in (select top 10000 Id from Customers where dbo.AccessRight(Id, 5) > 0) The second select statement should be replaced in code […]

Procedure or function 'stored_pr' expects parameter '@name', which was not supplied

I try to make a simpe app with asp and I have a problem. Procedure or function ‘stored_pr’ expects parameter ‘@name’, which was not supplied. My Stored Procedure: ALTER proc [dbo].[spq] @name nvarchar(max) as insert into tableq (name) Values (@name) GO My code in ASP: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; […]

Query to loop through one table and insert incrementally by group into another

I need some help with a sql query. I’ve got two simple tables, one that contains Channels, each with a unique identifier (ChannelID), and another one to many ID (OtherID). The second one will contain a sort order of each channel as it appears in another query. This sorting table is currently empty and my […]

How to insert data from listbox into database?

I have a listbox with two buttons. The first button to add a file into the listbox. The second button to delete it from the listbox. And there is a third button I want to use it to insert the files from the listbox to the SQL Server database. For example if I added two […]

Procedure or function has too many arguments specified SSRS

For some reason I am able to run my SELECT statement in SSMS, but when I use it in SSRS then it says Procedure or function has too many arguments specified. If I choose only one parameter – it gives me the result. But if I choose 2 or more – I got an error. […]

SQL Server query passing list of parameters containing numeric and character id's

MS SQL 2008 I need help with a query. I was working fine before but, now i am getting arguments that overlap rendering this query useless. Basically, i am passing a list of parameters in the format ‘1_s, 22_o, 1_u, 35_t’… where first token is numeric id and second it the type of the product […]

SQL query that finds repeated data in one column with different data in a second column

Let’s say I have data that looks like this: ID Date Data A D1 123 A D1 456 A D2 123 What I’m looking for is a select statement that will pull all rows where ID and Date are repeated as a pair, but the data doesn’t match. In this case, it would return the […]

Calculating SUM on 3 related tables

I have three tables that are in 1-to-many relationships. Since my business scenario is not easy to explain, I am going to use a more familiar terms: Customers -> Invoices -> InvoiceDetails Lets assume that there exist Customers.Value1, Invoices.Value2, InvoiceDetails.Value3, all of type double (real). I need to get the summaries of Value1, Value2 and […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.