sql-server

How to send mail from SQL server?

Hi! I started to use SQL for a few days, so i'm just a beginner. I want to do the following: I want to run a query in everey month, which gives back the data i need, then store it in an .xls file or something else, and then send it to some recipients. Can i do this fully automatically somehow in SQL Server 2005? Could someone give me an...

SQL query search ampersand &

Need to write a SQL query to search special character in a column. Text needed to search is 'R&D' but issue is that SQL server 2005 is taking it as a logical operator. Any help? ...

Finding Out If Datetime Is In a Specific Time Interval Using SQL

Hi everybody, How can I find out if a datetime column in my table is in a specific hour interval (e.g 13:07 - 15:15) and in a specific day (e.g Thursdays) in a SQL select statement? Thanks, ...

Delphi: How to get the query that is passed to the server when parameters are used

I have a query with parameters inside a Devart TMSQuery.SQL. Something like select * from customers where customer = :CustomerID in code I do // Delphi sqlcustomer.ParamByName('CustomerID').asinteger := 4; sqlcustomer.open; I want to debug and see the exact sql command sent to the server, if I try to use TMSQuery.sql I just have th...

Tool for finding the database bottlenecks in sql server

I would like a tool that monitors sql server while I test my application. THe applicatino will of course run different queries. From the tool I would like an output like: - this query was slow because index is missing on this field and this kind of info. But I'd like to have a way to highlight crucial data, there can be for example 10...

How can I find the windows service which hosts a particular SQL Server instance?

My application connects to an arbitrary (configurable) instance of SQL Server. If the instance is local, the application needs to ensure that the SQL service is started before connecting. Given the name of the instance, how do I determine the name of the service to start? ...

Why is a SQL query executing slower in PHP than in Query Analyzer

Hi, I have a query that takes 5 seconds to run in SQL Server Managment Studio, but it takes 33 seconds in PHP to run the same query using *$qid=db_query($countQuery);* Has anyone got any idea why this might be? We are using SQL Server 2000 which I do not believe is the problem. [edit] After doing some profiling we noticed that the exe...

Should I use a database trigger for the following problem?

Hi, I've been given the following task: An external source will write a name, datetime and value to a database table (table A) at random intervals. I need to copy this data to another table (table B) and delete the row in table A. If the name doesn't exist in a lookup table then the row needs to remain in table A until it does and then...

How to fast fill MS Sql 2005 wit data in c#

I crate temporary table in c# (one column, type int), later I want to put ~40 000 values inside (it will be constantly changing). What is the fastest way of doing it ? ...

Dynamic Declare statements SQL Server

Hi, I'm using the varchar(MAX) value for text but as I'm building up the huge SQL it cuts the ending off. Is there any way I can create a Dynamic Declare statement that I can then join together with others when executing the sql? e.g. something like: DECLARE @sSQLLeft + Convertvarchar(4),@index) varchar(MAX) ...

Configuring replication after mirroring - is this possible?

Hi, I'm currently setting up replication in order to produce a database that will be used to run reports and take load of the main database. According to the guide at: http://msdn.microsoft.com/en-us/library/ms151799(v=SQL.90).aspx You setup mirroring, which we use for high availability after the publisher has been configured. I was ...

Hibernate joined-subclass deadlocks with MSSQL

I'm using Hibernate with Joined-SubClasses to Map a class hierarchy to a database. Unfortunately this causes deadlocks when an object is updated while a different thread is trying to load the same object. With objects that are mapped to a single table this is no problem. This seems to be caused the way MSSQL acquires locks on the table...

converting date field format

I have a field with birthday as either '7/08/1986' or '07/08/1986'. I want to convert the value to like this '1986/08/07'. Simply converting from DD/MM/YYYY to YYYY/MM/DD. Kindly note down this is all in SQL Server 2005. Additionally, if the date is in single digit means still the output shd be shown in double digit like '07' not '7'. ...

How to send an email message using Microsoft Exchange Server from Sql Server 2005/2008?

I know how to send mail using an SMTP server specified in a mail profiler in the Database Mail of Sql Server. You would do it like so: EXEC msdb.dbo.sp_send_dbmail @profile_name = 'profile', @recipients = @email, @body = @body, @body_format = 'HT...

performance of union versus union all

I have to run a select statement across several tables. I am sure the tables return different records. I am anyway using UNION ALL. Is it better to use UNION or of UNION ALL in performance terms when I am sure the tables return different records? ...

Query Optimization Question

Assume I have the following query: Update LPMBonusReport Set BoxID = (Select ContainerSerialNumber From Wip.vwWorkItem Where SerialNumber = LPMBonusReport.SubID) The object Wip.vwWorkItem is a view. Assume there are 100 rows in the LPMBonusReport table. Would the view get materialized 100 times, once for each row in LPMBonusR...

SQL Error: Incorrect syntax near the keyword 'End'

Hi Need help with this SQL Server 2000 procedure. The problem is made difficult because I'm testing procedure via Oracle SQL Developer. I'm running the procedure to iterate column with new sequence of numbers in Varchar format for those who have null values. But I keep getting error, so a) I may have done a wrong approach b) syntax i...

SQL Server differential backup file size smaller than previous one ??

Hey, I have a production system running on an SQL Server 2008 DBMS, in Full recovery mode. I take a full backup each day at midnight, a log backup every two hours, and a differential backup every 6 hours (06:00, 12:00, 18:00, but not midnight as the full is taken then). In recent days however I've noticed that the diff backup filesize...

SQL Server: querying cross referenced against dataset not stored in tables?

I have (adjusted for the sake of simplicity) a table containing 2 columns - start and end, both of which are time stamps. These represent phone calls. I need to produce what boils down to a graph, with time along the X axis, and simultaneous calls along the Y axis. I can extract the number of concurrent calls at any given time quite ea...

How to find the name of longest stored procedure ?

Hello, I have a database which contains 100's of stored procedures. I want to find which the longest stored procedure in these. How can i find it? Currently i am using Select text,MAX(len(text)) from syscomments group by text; But i am not able to find the name of stored procedure in it. Thanks in advance :) ...