How do I make values from a SQL table be the headers of a View?

I have a table in SQL Server 2008 of the following sort: Headings: ‘ClientId’ ‘FieldName’ ‘Value’ Line1: ‘1’ ‘Company Name’ ‘Company1’ Line2: ‘1’ ‘Contract Type’ ‘Year’ Line3: ‘1’ ‘Login Details’ ‘13546’ Line4: ‘2’ ‘Company Name’ ‘Company2’ Line5: ‘2’ ‘Contract Type’ ‘Month’ Line6: ‘2’ ‘Login Details’ ‘46528’ Line7: ‘3’ ‘Company Name’ ‘Company3’ Line8: ‘3’ ‘Contract Type’ […]

Aggregating error messages in SQL Server procedures

Stored procedures allow for better abstraction and separation of concerns from an application point of view. At my company, there is a tradition of having DBAs write procedures and do all the DB work. And, it is a model that works, mostly. As a .NET developer, I use Resource files to aggregate all my error/success/validation […]

SQL Server 2008 : Multiple Queries in One Stored Procedure

I have 2 stored procedures that retrieve data from a table called Places. The procedures are called by C# code one at a time. These are the table columns. [ID] int NOT NULL IDENTITY(1, 1), [Name] varchar(150) NOT NULL, [Latitude] decimal(18, 2) NOT NULL, [Longitude] decimal(18, 2) NOT NULL These are the 2 stored procedures […]

Two query Sql Expression

I’m not sure if this can be done within crystal, but here it goes. There are two values that are needed to obtain more report information on this report. First is finding units sold… the second is finding the appropriate final price for reporting… My initial thought was to try and assign a query to […]

Cap symbol (^) in LIKE Clause not working properly

See the below example where ‘1|2|||1|’ like ‘%%|%%|%%|%%|[^3]|’ /* it will return true if the string between last two pipe symbols is not like ‘3’*/ The above code just works fine. In the same way I need to build a expression for the string between last two pipes not like 10 or 11. Or at […]

pulling data from MySql Server using SQL server openquery

I am trying to pull data from Mysql server using SQL server OPENQUERY function. When I run a query to count the records that are in thew mysql server I get the value no problem -this query works and it return the total records found SELECT count(*) AS total FROM OPENQUERY(LinkedServer, ‘SELECT * FROM mydb_name.users’) […]

Counting distinct members based on number of months in duration of time

I have a membership table with the following columns: Member_number | StartDate | EndDate XYZ | 01-Jan-2002 | 01-March-2002 ABC | 01-Feb-2002 | 01-March-2002 Basically, I want to show how many members were present in specific month. My problem is I don’t know how to break this time span into months. How can I see […]

Excel query showing different result than SSMS query

I have had an odd error I cannot explain. Basically, I am running a query to my SQL database using excel and am having non-existent data pop up when it comes to a very particular order in my database. Here is a simple query surrounding this order: select * from OR200100 where OR200100.OR20001=’0000793605′ Here is […]

Where is the MVC4 Scaffolding database located?

I have started working with an MVC4 project that has a DefaultConnection enumerated in the web config. (sql server 2005 on a shared dev server) In an attempt to use MVCScaffoling I’ve followed tutorials then when I run the scaffold controller tablename -force command line I reload the list of sql server database tables do […]

Find the company that has the smallest payroll

Hi i have the following database scheema. employee (employee-name, street, city) works (employee-name, company-name, salary) company (company-name, city) manages (employee-name, manager-name) I need to find Find the company that has the smallest payroll. I have written the following query but my trainer tells me its wrong. SELECT company-name FROM works GROUP BY company-name HAVING sum(salary) […]

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