sql-server-2005

Saving data in SQL Server database and then sending the email later

I have a data entry and editing form and in every data entry or update event, I have to send an email to a dynamic list of recipients. I have been sending the email as soon as the user clicks the save or edit buttons but am thinking of first saving the data to the database, and then sending the email later. I want to do this partly to im...

How to set unique key in SQL Server 2005 .?

How to set unique key constraint in SQL Server 2005? Not through script or query. ...

What is the difference between Primary Key and unique key constraint?

What is the difference between Primary key And unique Key constraint? What's the use of it?? ...

How to set more than one primary key for a table?

Is it possible set more than one primary key for a table? If it is possible as composite key - so how it can be used with application?? ADVANTAGES .? ...

SQL Query Result Problem

I have Two SQL Query Both Return select round(convert(float,'24367.723'),2) Result:24367.72 Second: select convert(varchar(20),round(convert(float,'24367.723'),2)) Result:24367.7 Why the Second Query Return exclude the last digit after converting to varchar Thanks in Advance ...

Can I return foreign key columns from table valued functions?

I want to use a table valued function and call it from within multiple stored procedures rather than repeat the same query across all the stored procedures, but for compatibility with a legacy VB6/UltraGrid app I need to preserve the foreign key references from the original tables. Within the table valued function I can specify a PRIMAR...

Use of Execute As User in SQL 2008

We are transitioning from SQL Server 2005 to 2008 and suddenly our Execute As User statements aren't working. Did something change between these 2 releases? ...

SQL Server 2005 Partition table by foreign referenced data

is there a canonical way to partition a table by referenced data to another table? for example timetable id datetime bigtable id timetable_id -- foreign key .. other data .. i want to partition bigtable by the datetime in timetable. thankx. ...

Use like in T-SQl to search for words seperated by an unkown number of spaces

I have this query: select * from table where column like '%firstword[something]secondword[something]thirdword%' What do I replace [something] with to match an unknown number of spaces? Edited to add: % will not work as it matches any character, not just spaces. ...

MS SQL Server 2005 GROUP BY and SUM

Hey all, i am trying to create a report to show how much is spent per HRCode. This is my SQL Query so far: SELECT * FROM tblWO as WO, tblWOD as WOD, tblWA as WA WHERE WOD.OrderID = WO.ID AND WA.HRCode = WO.AdministratorCode AND WO.OrderDate BETWEEN '2010-01-01' AND '2010-08-31' AND Approved = '1' ORDER B...

Sqlserver Table Time field constraint

In SqlServer 2005 I have a table with a TimeOfDay field that is a varchar(5). I want to limit the field value to valid times only (13:40,2:20). This is what I have so far ALTER TABLE tbl ADD CONSTRAINT ck CHECK (TimeOfDay like '[1-2][0-9]:[0-9][0-9]' ) I want the constraint to allow the first digit to be optional, but not having much ...

Show failure for SQL 2005 Job that executes Powershell script through CMD prompt, IF PS script fails

I have a SQL 2005 instance that runs a job that uses a Powershell script to rename the current SQL TX Log backup file by appending "-PrevDay" to it, (subsequently deleting the backup already named "XXX-PrevDay.bak" if it exists), and then run a full backup of the DB and a TX Log backup, if the DB is not in Simple mode. SQL Job kicks off...

How should i modify this SQL statement?

My SQL Server view SELECT geo.HyperLinks.CatID, geo.Tags.Tag, geo.HyperLinks.HyperLinksID FROM geo.HyperLinks LEFT OUTER JOIN geo.Tags INNER JOIN geo.TagsList ON geo.Tags.TagID = geo.TagsList.TagID ON geo.HyperLinks.HyperLinksID = geo.TagsList.HyperLinksID WHERE HyperLinksID = 1 returns these... HyperLinksID...

BCP Function sequence error when running proc with parameters

I have been trying to create a stored procedure that uses dynamic SQL to assemble a bcp command to export data from a parameterized stored procedure to a csv file. Was originally getting the host data file access issue that I think was filesystem permissions. Now I consistantly get the fillowing error when I run the proc: SQLState = S...

SSIS XML Task with a For Each Loop

I have transformed an XML file See this question for a complete description What I want to do know is take this xml task and have it preformed in a For Each Loop. I want all xml files in a specific directory to be transformed and the resulting file to be moved to seperate directory. It's not working. I'm getting the following error m...

Getting Parent of Parent in Self Join Table

I have self join table. This table is being used to join up to 4 level, i.e.; Region -> Country -> County -> Town How can I get Parent of Parent of Town. To do this up to two level this is the query SELECT t.ShortName AS Town, (SELECT c.ShortName FROM Locations c WHERE c.LocationId = t.ParentId) AS County FROM ...

SQL Server 2005 SUM

Hey all, this is my query string here: SELECT SUM(Total) as Total, AdministratorCode, SUM(WOD.Quantity) as thePass FROM tblWO as WO, tblWOD as WOD WHERE WOD.OrderID = WO.ID AND WO.OrderDate BETWEEN '2010-01-01' AND '2010-08-31' AND Approved = '1' ORDER BY WO.AdministratorCode But i keep getting the error: The ...

ASP.NET ERROR : Keyword not supported: 'provider'

My app fails at this line of code: Dim objConnection As New SqlConnection(Application("ConnString")) My connection string is: "Server=testAITSQL;Database=SSCommerce;UID=PlanoWebApp;PWD=XXXXXXXX;" I googled this problem and the solution for it was having a malformed connection string where the "provider" was being specified when it ...

SQL Server Reporting Services SQL server 2005 publish a report via web service

Imagine you have 2 applications Application A and Application B. Basically I would like to insert records that exist in Application A into Application B. Sql Server Reporting Server is available on Application A And I was wondering if it is possible to build a report that gathers the record that I need and then publish it as a web serv...

Bulk insert fixed width fields

How do you specify field lengths with the Bulk Insert command? Example: If I had a table named c:\Temp\TableA.txt and it had: 123ABC 456DEF And I had a table such as: use tempdb CREATE TABLE TABLEA( Field1 char(3), Field2 char(3) ) BULK INSERT TableA FROM 'C:\Temp\TableA.txt' SELECT * FROM TableA Then how would I specify the lengt...