sql-server-2005

SQL query using UNIONS and GROUP BY

Hi Guys! The Query: SELECT max(image_url), Model_Name FROM ( SELECT max(image_url), Model_Name FROM dbo.proinfo_vodafone WHERE Brand_name='Nokia' UNION SELECT max(image_url), Model_Name FROM dbo.proinfo_3 WHERE Brand_name='Nokia' UNION SELECT max(image_url), Model_Name FROM dbo.proinfo_t WHERE Brand_nam...

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...

full-text search sql server 2005

Hi, I have got hold of a sql server 2008 developer edition and this is my data: if exists (select * from dbo.sysobjects where id = object_id(N'test') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table test create table test ( Id INT IDENTITY NOT NULL primary key, data NVARCHAR(255) not null ) insert into t...

.NET TransactionScopes and SQL 2005 Lightweight Transaction Manager - Multiple Connections same SPID?

Hi Can someone shed light on what is happening behind the scenes with the SQL Lightweight transaction manager when multiple connections are opened to the same DB? With the below code, we verified that MSDTC is indeed not required when opening 'multiple connections' to the same database. In the first scenario (where Txn1 and Txn2 use E...

SQL Performance (Replace)

Hey, I have a table that has about 400,000+ rows. I am writing some pattern matching code but need to clean up a column before I do so. This boils down to doing a replace-like operation. I tried listing them all out one at a time... Update T_ADDRESS set ADDR_LINEONE = REPLACE(ADDR_LINEONE,' southeast ',' se ') Update T_ADDRESS set A...

Filter list by custom code in Reporting Services 2005?

Can you do this? The list filter I want to use looks like this: Expression Operator Value =Code.GetOccCat(Fields!accountnumber.Value) = =1 No dice. Basically, it acts like that function returns null as far as the filter is concerned, but when I take the filter off and put the exact...

Reusing tasks in SSIS

How can a task be reused in SSIS without copy/paste? For example, I'd like to use the tasks I've defined in an event handler for one executable in another executable, but not with all executables in the package. So far, I haven't found any solutions other than writing a complete custom component, which seems like overkill. Any suggestio...

Averaging large amounts of data in SQL Server

It is desired to perform averaging calculations on a large set of data. Data is captured from the devices rather often and we want to get the last day's average, the last week's average, the last month's average and the last year's average. Unfortunately, taking the average of the last year's data takes several minutes to complete. I on...

Complicated daily automatic insert query in 2 tables

I have the following tables with their columns (only the relevant columns are listed): Entry EntryID (int/auto-inc) EmployeeNumber (int) JustifyDate (datetime) EntryDate (datetime) Employee EmployeeNumber (int) CoreHourID (int) WorkingFromHome (bit/bool) Hour EntryID (int) InHour (datetime) OutHour (...

How to uninstall SQLExpress?

I am trying to uninstall SQLExpress (not quite sure what version) and am failing to do so. It shows up under "SQL Server 2005" in Add/Remove programs. When I click uninstall it says that it is scanning the configuration and then it closes down. Nothing happens. It still shows up in All Programs and Team Foundation Server (which I am ...

sql help please

Hi All, The following sql snippet below is a subselect of a parent sql. Is there a way to say, "If customer doesn't exist I want to run a different sql"? select orderdate, (select contactname from customers where customerID = 'ALFKI' or select 'No Customer') as contactname from orders I know this can be solved with a join but...

SQL 2005 - two tables Join on some id,

Let's say I have 2 tables. I want join them so that for every account I get 1 row where the account's information is there PLUS the primaryContact's information appended to the table. Is this possible? ID's are unique keys. ACCOUNT TABLE accountid | name | income | primaryContact 123456789 Jack Johnson 1...

SQL Error on Audit Trail Insert after Scope_Identity()

I'm trying to use a stored procedure to do an insert on a main table, then also insert that data into a historical data table. I don't want to use a trigger, but rather just do a simple insert of all columns into the history table. I am getting this error, however. "An explicit value for the identity column in table 'ipaudittrail' can...

SQL Server 2005/2008 Finding nth highest salary

For Finding nth highest salary I am using select salary from ( select distinct ROW_NUMBER() over (order by salary desc) as rownum,Salary from Employee )a where rownum=2 However if i have same salary like 70000 70000 60000 50000 50000 When executing the query i am getting second highest salary 70000 instead 60000 ...

how to get max value from more than one table

Hi everybody, i had the tables structure like below Table1 ------- Id SessionNo 1 1 2 2 3 2 Table2 ------- Id SessionNo 1 1 2 3 3 3 Table3 ------- Id SessionNo 1 1 2 3 3 4 from these three tables i need the output as SessionNo 4 please give me a query for this ...

how to import MS Access database into sql server 2005 using VB 6.0 ?

hi, i have a MS Access database and want to importing that into SQL Server 2005 without using import facility on SQL Server 2005 Management Studio. but i want to coding that through VB 6.0... please help me.... thx before... GLU ...

How can i use substring in SQL?

Possible Duplicate: How can I rearrange string with SQL? Declare @CustTotalCount as int Declare @CustMatchCount as int select @CustTotalCount = count(*) from ENG_CUSTOMERTALLY select @CustMatchCount = count(*) from Task where MPDReference in( select ENG_CUSTOMERTALLY_CUSTOMERTASKNUMBER from dbo.ENG_CUSTOMERTALLY) if...

TSQL/SQL 2005/2008 Return Row from one table that is not in othe table

I have to compare a row of one table that is not in another table TableA ID 1 2 3 4 NULL TableB ID 1 4 When comparing TableA with TableB ,the following o/p (NULL Can be ignored) ID STATUS 1 FOUND 2 NOT FOUND 3 NOT FOUND 4 FOUND I tried with SELECT case T.ID when isnull(T.ID,0)=0 then 'NOT FOUND' ...

SQL Server 2005 failed backup effect on transaction logs

I have an SQL Server 2005 instance whose full backup (.BAK) failed due to low disk space. However half hourly transaction log backups continue (.TRN). Assuming I have an older full backup, could these continuing transaction logs be used to restore the database? i.e. do the transaction log backups only run from the last successful back...