sql-server

Help with TSQL join query

Based on below 2 tables declare @t1 table ( Id int, Title varchar(100), RelatedId int ) insert into @t1 values(1,'A',2) insert into @t1 values(1,'A',3) declare @t2 table ( Id int, Title varchar(100) ) insert into @t2 values (2,'B'), (3,'C') I am trying to get the below output Id Title RelatedItems -------...

How to SQL SUM on With Statement?

Query: ;WITH SuperSelect AS ( SELECT DISTINCT DropshipPackinglist.CaseNumber AS 'CASE NO.', DropshipPackinglist.Quantity AS 'QTY' FROM DropshipPackinglist JOIN HuaweiDescription ON DropshipPackinglist.ItemNumber = HuaweiDescription.ItemNumber WHERE (DropshipPackinglist.BatchCode ='0003721008190AHWA01KG')) SELE...

Visual studio 2010: no data source

I run Visual C++ Windows Forms application and MS SQL server 2005. I succeeded to connect to server and view table contents (tools -> connect to database), but when I try to add new datasource, nothing is found by wizard. Why? ...

web programming choice - language, database, reliable hoster and auto-scaling

Could you please suggest - programming option? Our Web application could have 60000 database requests/second or more in future. Which is better: MS-SQL or MySQL or other? Which is better: Asp.net, PHP, JSP or other? What kind of webhosting is reliable for auto-scaling? Any good webhosters or hosting plans? Thanks a lot. ...

SQL Server cross database query when the other DB name is not known in advance?

Given a multi-tenant setup with one database that holds the tenant data, and one database for each tenant, how can you construct a query to look up the same piece of data in each tenant database? eg The tenant master database has a table called Tenants: [TenantMaster].[dbo].[Tenants] Id, Name, DatabaseName 1, Bob, bobs_db_name 2, Kate,...

Understanding deadlocks with SQL Server query notifications

Hi I'm running into trouble with Query Notifications on SQL Server 2008 sp1. I have a table _sys_Events that multiple writers write entries into, and multiple readers perform SELECT statements with Query Notification to get latest entries immediately (this is done through .Net System.Data.SqlClient.SqlDependency class). Our database is ...

SQL connection issue from sharepoint after messing with service accounts

Hi, I had a win7 x64 box with a local Sharepoint 2010 installed on an SQLEXPRESS DB. Last week I also installed an SQL 2008 R2 instance with integration and analysis services next to the existing database. Because I had issues deploying analysis services solutions, I messed around quite some with the SQL Services Accounts. Eventually...

Searching in multiple tables using MS SQL Server 2000

We have a database with a lot of information about Persons. I won't post the entire database structure because it is too big, but it looks something like this: Person ID Name Street City State Country Language LangCode Language Interest ID LastChangedBy LastChangedOn LocalizedInterest InterestID LangCode Description PersonInterest...

Update multiple tables in a single update statement with left join

I realise what I'm asking for may be impossible. I want to perform an UPDATE on two separate tables based on a LEFT JOIN and a WHERE clause. This is my attempt: UPDATE PERIODDATES as pd, periods2 as p2 SET pd.[PERIODCODE] = @PERIODCODE, p2.[USERCODE] = @USERCODE left join periods2 AS p2 ON pdates.schemeid =...

SqlException.Message duplicated when calling sqlserver stored proc

I have a stored procedure that gives a friendly enough error that I want to show to the users but when I call it from .net it comes out twice. When I call the proc from sql server management studio it only comes out once. Here is a cutdown version of the stored proc: ALTER PROC [Production].[spDoSomething] ( @PassedID int) ...

Get the 2 digit year in T-SQL

I need to get the current 2 digit year and increment by one. So the current number I'm looking for should be 11. Probably really simple but I'm a sql noob :) Thanks ...

How can I GeoCode a table of addresses in SQL Server automatically?

Hi, Is there a way to geocode a table of addresses so that latitude and longitude columns can be updated with the correct details. Ideally I would like a system that will operate every so often, geocoding any address that did not have a lat / long. Currently there are areound 30,000 addresses in said table. Thanks in advance Edit Th...

The EXECUTE permission was denied on the object 'xxxxxxx', database 'zzzzzzz', schema 'dbo'.

Exact duplicate of The EXECUTE permission was denied on the object 'zzzzzz, database 'xxxxxx' schema 'yyyyyy', I'm having problems executing a function... Here's what I did: create a function using sql server management studio. it was successfully created. i then tried executing the newly created function and here's what I...

The EXECUTE permission was denied on the object 'zzzzzz, database 'xxxxxx' schema 'yyyyyy',

I'm having problems executing a function... Here's what I did: create a function using SQL Server Management Studio. It was successfully created. I then tried executing the newly created function and here's what I get: The EXECUTE permission was denied on the object 'xxxxxxx', database 'zzzzzzz', schema 'dbo'. ...

Why does SQL Server Management Scripting ignores the version?

I need to increase the size of a field in a table from VARCHAR(100) to VARCHAR(255). For different reasons, this causes the table to be dropped and recreated (along with relationships, FKs, etc). That is acceptable however, I’m performing this change in a SQL2008R2 (express) (or 2008 Express, same result), but the script doesn’t work in ...

Handling IS NULL inside string in SQL

I have a SQL query which is written in string and then executed using command Exec(string) like the following : Declare @TestId bigint = null Declare @Query nvarchar(max) set @Query = 'SELECT * from Registrations where RegistrationId = 15 AND (' + CAST(@TestId AS NVARCHAR) + ' IS NULL OR TestId = ' + CAST(@TestId AS NVARCHAR) + ') ' EXE...

Validate a code written by students

I teach SQL Programming in an university. I was thinking to create a submit page that they could upload the .sql file and it automatically checks if the requirements were met, such as creating a database, using a custom CLR dll and so on. Does anybody have experience in creating that? I got a server running Windows for that. Thanks in ...

How to determine global and local mins and maxs in sql server 2008?

I am trying to figure out the best way to determine global and local mins and maxs for a data set. I think there has got to be an easy way to do this but I cannot figure it out. I am using Sql Server 2008. Lets say I have a data set of subscription dates for users. Start Date Stop Date PersonID 12/31/2007 3/31/2008 ...

Entitiy Framework - DB round trips

I would like to know if exists a way to log all DB trips from Entity Framework. I have google it, but I didn't found ...

Using SQLDependency/SqlNotificationRequest to have multiple instances of the same app receive the same notifications?

I started looking at this recently with the very limited knowledge that the ASP.NET Cache could somehow make use of a SqlCacheDependency to invalidate the cache when a table (or a queries results) change. This lead me to the SQLDependency and SqlNotificationRequest classes. While the details of the SqlNotificationRequest class still e...