sql-server-2005

Is there any way to index a varchar column as a datetime?

I'm querying a varchar column that contains all valid datetimes. In the query, I cast the column to datetime. Keep in mind, changing the column's datatype definition to datetime is not an option. Just trust me, it's not an option. Through query analysis, I see that the query would be much faster if I could add an index on this column....

select top 3rd record from a column in sql

how to select top 3rd record from a column in sql ...

How can make Column that allow null to be unique from SQL Server 2005 ?

I have column in a table that allow null but i want to make constraint that make him null or unique ... How can i do that ? Note : I validate it from the frontend but i want to have a physical in sql server that allow this even developer try to enter data ...

Tsql: can i use a variable as database reference

Hi, i want to accomplish this: update @sourceDatabase.dbo.PredictedPrices and then set @sourceDatabase as a variable. But i'm not allowed? Incorrect syntax near '.'. Is there another way? ...

T-SQL - In Single Stored procedure want to pass value(result) of one query to another query as input.

Hi All, I have a Stored procedure, in which I have to insert 3 strings into 3 different Tables at a time, each string into each of the 3 tables. In each table, a unique primary key (rowid) would be generated on insertion of the value. Now, the Primary Key of first two tables is the Foreign key of the Third Table which as you all know, sh...

Getting an error while restoring logs in LOG SHIPPING environment

Hello, I'm working with SQL SERVER 2005 SP2. I have a working and a steady environment of LOG SHIPPING for quite a while. Yesterday, the Restore job of the LOG SHIPPING in the DR server failed with the locking error (the log starts from the last line and goes up): 05:02:38.34 *** Error: The log backup file 'C:\database\LogShipping\2...

SQL 2000/2005/2008 - Find Unique Constraint Name for a column

Hi, I have a table with a column that needs the data type upgrading. However running any alter script causes errors due to a unnamed unique constraint. I need to drop this constraint but unfortunately I do not know the name. I have a script which currently lists all the unique constraints on the table but I need to find out how to go...

Consecutive streak of dates

Hi, Hopefully this isn't a dupe of another question, but I couldn't see it anywhere else - also this is a simplified version of another question I asked, hopefully to get me started on working out how to approach it. I am looking to work out consecutive ranges of payments where there has been at least one payment in each month. I have ...

how to take backup from plesk panel?

hi.. I want to backup my database from the plesk panel.. I followed the steps given in the help tab in the plesk panel.. it too took a backup and allowed to download it.. but the downloaded file contains 0 bytes.. Then how can I take backup of my database from that panel??? Can anyone help me in this please...??? thank you.. ...

SQL Server XML Extract Nodes

I am using SQL Server 2005 to Extract XML data. I would appreciate some help extracting the following XML snippet? <ELEMENT_A> <CHILD_A _attribA="ABC"> <CHILD_B Type="1"> <CHILD_C> <CHILD_D Type="1" Date="2010-08-31"> <CHILD_E _attribB="M0"> <CHILD_F>-0.32295</CHILD_F>...

sql server 2005 problem - defrag necessary?

Hi, I insert some data into a sql server 2005 database using NHibernate. Before I insert an object I check whether it already exists based on its primary key. Every 100000 or so lookups this seems to throw some exception (if I do the same via sql it takes ages as well). A defragmentation of the hard disk seems to help but seems a bit st...

.Net Windows Service - NT Authority\System - Login Failed

We deploy software on a dedicated server. It's a Windows 2003 server with SQL Server 2005 and IIS. We have four .Net Windows Services that run on the server. At one client location two of the four services are failing to connect to the database following a reboot. The error for both is "Login failed for user 'NT Authority\System'"...

optimizing the DELETE statement with a count

Which of the following two statements would you consider to be the most effective for deleting large number of rows? Statement #1: DELETE TOP (@count) FROM ProductInfo WHERE productId = @productid Statement #2: Derived table DELETE t1 FROM (SELECT TOP (@count) * from ProductInfo WHERE productId = @productId v) t1 ...

Updating SQL column based on text file (foreach line in it)

What I have is an extremely large text file that needs to go into a specific column at a specific raw. The file is around 100k lines. So what I want to do is read the whole file, and for each line append into that specific SQL column the line. Here's what I have but i really need help on the SQL query string[] primaryfix = File.ReadA...

SQL what is wrong with the syntax here?

What is wrong with the syntax in this function? I am getting the following errors: ALTER FUNCTION [dbo].[udf_ReportingLevelStructure2] ( @CompanyID INT ) RETURNS @result TABLE ( CompanyName VARCHAR(300), [rl_Index] INT, [rl_Addr1] VARCHAR(MAX), [rl_Addr2] VARCHAR(MAX), [rl_DisplayName] VARCHAR(MAX) ) AS BEGIN ...

How to get value of deleted test in trigger?

Hi I need to put a trigger on Delete on Table1. On delete of record from Table1, I need to update Table2 in trigger, but i need the value of deleted record in the trigger. Example:- IF OBJECT_ID ('UpdateLog','TR') IS NOT NULL DROP TRIGGER UpdateLog; GO CREATE TRIGGER UpdateLog ON Table_1 AFTER DELETE AS UPDATE Table_2 SET D...

SQL Server 2005 seperate stored procedure CSV value into multiple columns?

I'm a SQL Server 2005 newb and I have to do something that should be easy but I'm having difficulties. For the time being my stored procedure is storing csv in one column in my db. I need to break apart the csv into multiple columns. The number of values in a the CSV parameter is static, there is always gonna be 8 values and they are al...

SQL concatenation inside VBA string

I'm using VBA excel 2003,SQL 2005 to make a sql query call and inside my sql statement I'm using '+' operator to concatenate two strings. dim query as string query = "Select distinct ', '+emailaddress1 " query = query & "from contact " would this work inside vba? My query returns too many records in excel but not in SQL? Please just...

SQL Server 2005 - Inserting records using OpenXML vs delimited string

I have a bunch of employee names which need to be inserted in a table. Should I represent my data like this and use OpenXML to insert into the database:- <Employees> <Employee> Emp1 </Employee> <Employee> Emp2 </Employee> <Employee> Emp2 </Employee> </Employees> OR I should represent the Employee like Emp1,Emp2,Emp3, split the strin...

SQL server, is there any central table to get meta data of all tables?

I have to query in SQL server about which table is having maximum data and which one is having minimum data. Please tell me how can i do this.. i am runninf SQL server 2005. ...