sql-server

select a distinct row in left join

Table 1 ID 1 2 3 Table 2 ID date opt 1 1/1/10 1 1 1/2/10 0 2 1/1/10 1 I Want ID date opt 1 1/2/10 0 2 1/1/10 1 How do I join these 2 tables? Just match all the ID's in table 1 with their most recent opt in table 2. Without partitions, please. I'm in sql 2005. Thanks. ...

Grant user DDL permissions on specific schema

Using SQL Server (2008), is it possible to grant a specific user full control of the objects under a specific schema? This includes create/drop/alert table. Its important that this user isn't not given db_ddladmin role because that would give him access to other tables. ...

Detecting the record that was updated within a Trigger

Hello, I have a SQL Server 2008 database that has a Trigger. This trigger is defined as follows: CREATE TRIGGER [dbo].[Trigger_Car_Insert] ON [dbo].[Car] FOR INSERT AS UPDATE [Lot] SET [TotalCars]=lotCars.TotalCars FROM [Lot] l JOIN ( SELECT c.[LotID], COUNT(*) as 'Tot...

I am having trouble getting the correct results using XML EXPLICIT in T-SQL (SQL Server 2008)

I am getting strange results from a query using XML EXPLICIT mode in T-SQL (SQL Server 2008). Can someone explain what I am doing wrong? Here is my example: declare @parents table(id int, connection int, title nvarchar(255)); declare @children table(id int, connection int, title nvarchar(255)); insert into @parents(id, connection, ti...

SQL Query Problem -- Are Pivots Necessary?

Given the following data: CardholderID Source DateTime -------------- ---------------------------------------- ----------------------- 3 2nd_Flr_Ramp_Out_Reader 2010-06-30 13:58:42.410 3 2nd_Flr_Ramp_In_Reader 2010-06-30 13:44:22.417 3 ...

'Printing' from a SQL 2008 R2 trigger

If I have PRINT 'something' in a trigger, where does that output go? I'm using SQL Server 2008R2 ...

SQL Server Stress Test Tools?

I am looking for a stress tool for SQL Server. I've seen a lot of suggestions on Google. But nothing of what I really need. I look for: I really look for a tool that could run a list of stored procedures in parallel to see how much contention on resources. The collect and reporting feature is not that important. But I also want somethi...

Forward Engineering to SQL Server from MySQL workbench?

Is possible to forward engineer to SQL Server from MySQL workbench? ...

Determining the current security checks being made (SQL Server)

One thing that I've always hated more than just about anything in MS SQL Server is the way that security works. The security context constantly switches if you look at the server funny and it's often very hard (for me anyway) to predict or debug. In dealing with an issue today, I though, "I wish I could just add a line to my code that w...

SQL Server adding values

Hi, SELECT @s = ISNULL(@s + '. ' , '') + [Comments] FROM [Customer] RETURN @s How can I catch Null or '', so that if its either It Won't append to the string and not add a '.' Thanks Jacob ...

TSQL CASE WHEN THEN SYNTAX - USING REPLACE

Hi there, This actually applies to a prior question, TSQL 2008 USING LTRIM(RTRIM and Still Have Spaces I am at the point of writing a very lengthy SELECT statement using OMG PONIES statement to remove NON NULL non visible characters (WHEN PropStreetAddr is NOT NULL THEN (SELECT LTRIM(RTRIM((REPLACE(PropStreetAddr, ...

Dot Net Nuke Installation

I am new to Dot Net Nuke. I downloaded and tried to install it onto Windows Server 2008. It installs to the point where it starts running scripts for the database. I choose SQL Server 2005/2008 as the database and put in the correct Database name and connection string with the correct credentials as well. It however fails after running a...

what is the equivalent query in mysql?

Query 1: Top 10 codes that takes maximum time select top 10 source_code, stats.total_elapsed_time/1000000 as seconds, last_execution_time from sys.dm_exec_query_stats as stats cross apply(SELECT text as source_code FROM sys.dm_exec_sql_text(sql_handle)) AS query_text order by total_elapsed_time desc ...

Restrict rows included in a SQL Server full text catalog

Is it possible to restrict the rows that are included in a FT catalog for a given table? For example, I would want only rows with IsActive=TRUE to contribute to the catalog and be searchable. Possibly this may reveal a lack of understanding on my part of FTS. I'm wondering whether there would be advantages in performance if the catalog ...

What is faster reading an XML file or querying a database

I am designing a CMS in C# and need to decide where to save configuration settings for the site. Also considering defining my base html templates and then processing them server side to create the pages ahead of time. So what is generally faster/less overhead for the server reading an XML file or querying that same information from a l...

difference between procedure and stored procedure sql server?

What is the difference between a procedure and a stored procedure on sql server? ...

How to convert second into datetime's 108 format hh:mm:ss in sql server without writing function

select v1.*, datediff(ss,v1.dateofchange,v2.dateofchange) as acutaltime from vActualTime v1 left join vActualTime v2 on v1.rowno=v2.rowno-1 FK_PatientId FK_Status_PatientId DateofChange rowno acutaltime ------------ ------------------- ----------------------- -------------------- ----------- 3 ...

If I restore a database and overwrite the original is there any way to go back? SQL Management Studio

I do not have a backup available but I wrote over an existing database with a backup file. The problem is the one I wrote OVER had a Stored Proc that I need to get back. Any way to do this without a backup file of the database with the Stored Proc in it? ...

SQL Constraint IGNORE_DUP_KEY on Update

I have a Constraint on a table with IGNORE_DUP_KEY. This allows bulk inserts to partially work where some records are dupes and some are not (only inserting the non-dupes). However, it does not allow updates to partially work, where I only want those records updated where dupes will not be created. Does anyone know how I can support I...

how to make a facebook-like social network

I started since a while making a new social network using ASP.NET with C# just like facebook and I found that it doesn't make sense to make something already exist . but i don't care :D I'll make it any way and I need to your opinions about the database design for the news feed, friends and comments !! News Feed SenderId - ReceiverId ...