sql-server-2005

The result of [Datetime + 420./1440] (7 hours) is wrong (precision in ms is lost)

Could pls explain why I' not able to get valid result ( with precision to miliseconds ) after doing this (adding 7hrs to date): select getdate() as dt into #t1 select dt, dt+(7.*60/1440) as dt_new from #t1 I got: dt dt_new 2010-10-25 04:56:33.640 2010-10-25 11:56:33.580 As you can see there is difference in 60m...

Help determining proper Identity Range sizes

I have a Merge Replication with ~200 subscribers. I am trying to determine what would be appropriate Identity Range Sizes on some of the tables. You see I inherited a DB structure that was not designed for Replication therefore all table PK's are int IDENTITY's. Unfortunately some of these tables were built WITHOUT any tracking fields...

SQL Server data to HTML layout

Hey all, I am trying this code below to be placed into my own HTML layout for export to a PDF. SELECT DISTINCT i.InvoiceNumber as 'Invoice', '$' + CONVERT(varchar(50),round((CONVERT(int,Points) * .1),0)) AS 'Amount', '$' + CONVERT(varchar(50), 1.50) AS 'Fee' FROM tblHGP HGP, OrderDetails OD, tblInvoices i JOIN tblCS cs ON i....

SQL UNION on 2 table variables where date is same but other data is not

I have 2 table variable @Data and @DateTable @Data conatains the following: Company Date Type Select Altec 12-1-2010 d 2 Altec 12-1-2010 a 2 Alect 12-3-2010 d 3 @DateTable contains the following: Company Date Type Select Altec 12-1-2010 a 0 Altec ...

How to dynamically choose which table (with same schema) to select from in stored procedure

I have a bit of an odd database model for a project - I'm going to have several tables with the same definition. Each table stores information for different clients and because of security restrictions, we cannot put the data together in one table. So it would look something like this... table ClientOneData ( Id (PK, int, not nul...

What is wrong with the syntax of this OUTPUT statement (SQL Server 2005)?

I'm trying to use the OUTPUT statement in a stored procedure in order to return the ID of a newly inserted row. The stored procedure is: CREATE PROCEDURE PROC_RESTORE_REQUEST_TO_QUEUE @cs_uri_stem varchar(900), @cs_uri_query varchar(2500), @date datetime, @time datetime, @queue_state smallint, @process_id int, ...

how to start a sql server agent job from java code

I have few SQL Server Agent Jobs running in my project. The jobs run perfectly as scheduled, no issues. But now I need to be able to start these jobs from the front end (Like on a click of button or so). How can I do it ? Do these jobs behave just like a functions ? ...

Unable to update sys.columns - any other approach?

Hello! I just found out, that since I created my DB on a different server that had a different collation, then immigrated to a new server with new collation, now I keep on having trouble, and I decided to change all the values of the old collation. So I tried to execute this query: sp_configure "Allow Updates", 1 GO RECONFIGURE WITH O...

Suggest good links for working with insert delete update create in SQL Server using C#

I cannot remember the site, but I showed parameter add etc where we could add the name of parameters instead of forming the whole query as a single statement Please suggest some good links having coding info for working with SQL Server tables using C# website, following needed most create table insert data delete data declare primary ...

SQL Server 2005: Attach database using sp_attach_db with full text catalog

Having issues attaching a Database and full text catalog from server A to server B with the "sp_attach_db" command in SQL Server 2005 SP3. All the database files (data, log, full-text catalog) have been copied from server A to server B. I am guessing that this is indeed possible and that my syntax is just incorrect, but I can't seem to f...

Using cast or convert to convert negative int values to datetime in SQL Server

I have some negative integer values which are an offset from the default 1-1-1900 date. I have to get the datetime values from these. How can I do this. Example: If I do: SELECT convert(datetime, 53691) as Calc OR SELECT cast(53691 as datetime) I get: 2047-01-01 00:00:00.000 What I need is that If I do: SELECT convert(datetime, ...

Custom Logging within sql server 2008 Scheduler Job > View Histroy?

I am creating sql server 2008 Agent scheduler job form sql script. Want to Log the details if failed in some case within Job > View Histroy. Is there any way, so we can log custom text with Job > View Histroy? ...

Can not access SQL 2005 ?

the SQL has been installed but there is no server name and the Program does not accept any server name , and all the options , like the TCP , ports and Remote access are enabled ...

Catch errors and log in SQL Server 2005

I have big script with many INSERT operations. Some of them maybe have mistakes, so I want to write them into a temp table. What is the best way to do this? ...

Cannot access SQL Server 2005?

A specified SQL Server instance name is not valid. ...

Null value column and NOT EXISTS T-sql

Hi, I'm trying to do the following: IF NOT EXISTS ( SELECT * FROM [tbl_web_company] WHERE [name] = @name AND [address1] = @address1 AND [address2] = @address2 AND [city] = @city ...

How to remove accents and all chars <> a..z in sql-server?

I need to do the following modifications to a varchar(20) field: substitute accents with normal letters (like è to e) after (1) remove all the chars not in a..z for example 'aèàç=.32s df' must become 'aeacsdf' are there special stored functions to achieve this easily? UPDATE: please provide a T-SQL not CLR solution. This is ...

Select's Where Clause - Non Ascii Characters?

Hi, I'm having a problem with non-ASCII characters in a where clause Say for example a record in my table has : column_a Bom D� Street And I want to see if this will find the record: SELECT * FROM [tbl_test] where column_a = 'Bom D� Street' This always returns no records. Is there something you have to do to handle non-ASCII char...

Delete All / Bulk Insert

First off let me say I am running on SQL Server 2005 so I don't have access to MERGE. I have a table with ~150k rows that I am updating daily from a text file. As rows fall out of the text file I need to delete them from the database and if they change or are new I need to update/insert accordingly. After some testing I've found that ...

TSQL Function to calculate 30 WORKING days Date from a Specified Date (SQL Server 2005)

TSQL Function to calculate 30 WORKING days Date from a Specified Date (SQL Server 2005)? Input parameters would be Date and Number of Working Days. Output would be the Calculated Date. This would exclude Saturday, Sunday, Holidays and Day Holiday was observered. i.e. If the Holiday falls on a weekend but it is observed on the Friday ...