sql-server-2005

any way to simplify this LIKE wildcard expression in T-SQL, without resorting to CLR?

I have a column of database names like so: testdb_20091118_124925 testdb_20091119_144925 testdb_20091119_145925 ect... Is there a more elegant way of returning only similar records then using this like expression: select * from sys.databases where name LIKE 'testdb[_][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][_][0-...

How do I copy a DB from the server to the application's AppData folder?

Hello folks, I've been working on an ASP.NET application accessing a DB in my local machine. Now I want to have this DB in the app's AppData folder instead, so I can easily work on it from within VS SQL instance accessing the mdf file, and easily copy and share it between programmers. Thanks a lot! ...

SQL Replication snapshot deployment from SQL2005 to SQL2000 bcp parameters incorrectincorrect

I am replicating using transactional replication from SQL2005 to SQL2000 however the deployment of the snapshot is failing on the bulk insert of the data into the subscriber tables (works fine to a 2005 subscriber), providing the following error details: Error 'The process could not bulk copy into table '"dbo"."tableName"'. (Source: MSS...

Limiting SQL Temp DB Growth

Hi GUys, I am facing a serious issue in my production server where the temp DB grow exponantialy. Is there any way we can recover the tempDB space without restarting the SQL service? Cheers Kannan. ...

SQL Sever Management Studio for SQL Server 2000

We use mostly SQL Server 2005 but have a few SQL Server 2000 servers laying around. Is there a SQL Server Management Studio like application for SQL Server 2000? Thank you. ...

SELECT TOP 1 in a many to many query

I have a faily simple many to many schema, which looks like this: What I'm trying to do is select all players with some arbitary conditions and I also want to select their most recent match, if they've played in one. What I've managed to do is: SELECT tblPlayer.PlayerId, tblPlayer.Surname, tblPlayer.Forename, (SELECT TOP 1 tblMatch.Ho...

Update Field based on another table's values

Is there a more elegant way to write the following Microsoft SQL Server 2008 command? UPDATE TableB SET TableBField2=0 WHERE TableBID IN( SELECT TableBID FROM TableB JOIN TableA on TableB.TableAID=TableA.TableAID WHERE TableBField2 < 0 AND TableAField1 = 0 ) In plain speak, what I'm doing is updating a table ...

SQL Server 2005 user prioritization

I currently have a SQL Server 2005 database that is accessed by multiple users. Is it possible to have SQL give processing priority to specific users based on their login names? ie, if Alice and Bob are both running queries simultaneously, I want to ensure that Bob is given priority over Alice. ...

sql query tree like structure

I have a tree like structure of Categories, the leaf Nodes in the tree have Products and the products have Cods I need to select all the top level Categories (parent=null) that have leafs (Cods) that match some critaria... SELECT Category.Id AS Id0_, Category.Name AS Name0_, Category.COrder AS COrder0_, Category.Des...

How can I programmatically retrieve the alter view script for a view in SQL Server 2005.

We allow our uses to alter certain views for reports and what not based on some application field meta data that we keep track of in our application. These fields can be created at run time. I have a standard process in place to alter the views when a field is added or removed. I now need to do this programmatically however, which mea...

how to get last 10 records form sql table in asc order....

select top(10) from customer order by customer_id desc ...

SQL Server 2005- Add area code to records shorter than 10 characters

Can anyone come up with a SQL routine or ideas to systematically append an area code to the beginning of every field in our SQL Server 2005 database that does not have an area code in it? Perhaps someone could tell us how to return only rows that are less than 10 characters long and how to append the 3 digit area code to the beginning ...

Subgroup Count in SQL

Hey all, I have a query that looks like the following: select c.[Name], c.Description, c.ID, cd.StartDateTime from Classroom.dbo.Class as c left join Classroom.dbo.Course as co on co.ID = c.CourseID left join Classroom.dbo.Classdate as cd on cd.ClassID = c.ID where co.PublicIndicator = 1 This query simply gives me a list ...

VB.Net 3.5 and SQL Server 2005 Windows Chat Application

Hi Currently following is the project I need to submit for my college assignment: A vb.net chat application with a ms sql server 2k5 backend, max 100 users with file transfer, one to one and group chat facility. Admin will create chat rooms which will be password protected for group chats. We will need to implement multithreading to fect...

who deleted a SQL table?

Hi, In the production server i see that there were 2 important table which got suddenly missing. This was an absolute surprise for us. due to this our application went down. Finally we could create the tables back using the old backups and the applicaiton came to normal state after that. now the question is who deleted the tables, how ...

SQL Server get next previous rows from a table based on a date

I have the following SQL Server query and I am trying to get the next and previous row from a given Id. All works great unless there are two/more dates that are the same, then my logic breaks down. If you set @currentId = 4 then I get back id 7 (it should be id 6) for the prev If you set @currentId = 6 then I get back id 2 (it should ...

SQL server insert data from table into an XML variable

How can I insert a whole bunch of rows into an XML variable without using a cursor? I know I can do SET @errors.modify('insert <error>{ sql:variable("@text") }</error> as last into /errors[1]') to insert the value of a variable, but I want to basically do SET @errors.modify(SELECT 'insert <error>{ sql:column("text") }</error>' FROM t...

I m using one database with the same name in SQL Server 2000 and SQL Server 2005.

I am using one database with the same name in SQL Server 2000 and SQL Server 2005. How can I manage the connection string in the web.config file so that we can differentiate the connection. While we are using the same user name and password for the both databases. ...

SQL Server single user mode

Im experiencing an issue with a production server. I can connect to the server from only one program at a time. Eg, when I connect from SQL Management Studio then nobody else can, and vice versa with a different user. It's like the server is in single user mode, except, it's in multi user mode. Any ideas? I get this error message when ...

efficiency of SQL 'LIKE' statement with large number of clauses

I need to extract information from a text field which can contain one of many values. The SQL looks like: SELECT fieldname FROM table WHERE bigtextfield LIKE '%val1%' OR bigtextfield LIKE '%val2%' OR bigtextfield LIKE '%val3%' . . . OR bigtextfield LIKE '%valn%' My question is: how efficient is this when the number o...