sql-server

sql-server: how to select from dupilcate rows from table?

Hi All, I have the following table. CREATE TABLE TEST(ID TINYINT NULL, COL1 CHAR(1)) INSERT INTO TEST(ID,COL1) VALUES (1,'A') INSERT INTO TEST(ID,COL1) VALUES (2,'B') INSERT INTO TEST(ID,COL1) VALUES (1,'A') INSERT INTO TEST(ID,COL1) VALUES (1,'B') INSERT INTO TEST(ID,COL1) VALUES (1,'B') INSERT INTO TEST(ID,COL1) VALUES (2,'B') I ...

Remove duplicate from different columns in SQL Server 2000

I have table : number city1 city2 mentions 1 a b 5 1 b a 5 1 c d 2 1 d c 2 what I need is to remove duplicate records, such as a, b equal to b,a became : number city1 city2 mentions 1 a b 5 1 c d 2 any clue for me ? thanks before :) ...

sql-server: Can I update two table with Single Query?

How can I write single UPDATE query to change value of COL1 to ‘X’ if COL2 < 10 otherwise change it to ‘Y’, where the following two tables are linked by ID CREATE TABLE TEMP(ID TINYINT, COL1 CHAR(1)) INSERT INTO TEMP(ID,COL1) VALUES (1,'A') INSERT INTO TEMP(ID,COL1) VALUES (2,'B') INSERT INTO TEMP(ID,COL1) VALUES (11,'A') INSERT INTO TE...

Sync Framework Peer Data Sharing Unable to Catch Conflicts, Source Provider Alwasy wins!

Hi, I am using SQL Server 2008 and the WebSharingAppDemo-SqlProviderEndToEnd sample and this is almost perfect for my needs however I am unable to detect conflicts. By default ConflictResolutionPolicy is set to ApplicationDefined. I have tried setting the ResolutionPolicy to SourceWins, DestinationWins or ApplicationDefined and I alwa...

SQL Server: how can I list distinct value of table in a single row, separated by comma

I have the following table: CREATE TABLE TEMP (ID INT, SEGMENT CHAR(1), SEGOFF INT, CHECKED SMALLDATETIME) INSERT INTO TEMP VALUES (1,'A',0,'2009-05-01') INSERT INTO TEMP VALUES (2,'B',1,'2009-05-01') INSERT INTO TEMP VALUES (3,'C',0,'2009-05-01') INSERT INTO TEMP VALUES (4,'A',0,'2009-05-02') INSERT INTO TEMP VALUES (5,'B',2,'2009-05-...

SQL Server database with clustered GUID PKs - switch clustered index or switch to sequential (comb) GUIDs?

We have a database in which all the PKs are GUIDs, and most of the PKs are also the clustered index for the table. We know that this is bad (due to the random nature of GUIDs). So, it seems there are basically two options here (short of throwing out GUIDs as PKs altogether, which we cannot do (at least not at this time)). We could chan...

SQL Server 2008 Running trigger after Insert, Update locks original table

Hi Folks, I have a serious performance problem. I have a database with (related to this problem), 2 tables. 1 Table contains strings with some global information. The second table contains the string stripped down to each individual word. So the string is like indexed in the second table, word by word. The validity of the data in the...

How to avoid using duplicate savepoint names in nested transactions in nested stored procs?

I have a pattern that I almost always follow, where if I need to wrap up an operation in a transaction, I do this: BEGIN TRANSACTION SAVE TRANSACTION TX -- Stuff IF @error <> 0 ROLLBACK TRANSACTION TX COMMIT TRANSACTION That's served me well enough in the past, but after years of using this pattern (and copy-pasting the above c...

Does an insert made in a transaction is visible by SELECT before transaction is commited

I need a confirmation. Client 1 insert rows in a table inside a transaction. Client 2 request this table with a SELECT. If on this client isolation level is set to READ COMMITTED, can you confirm that the SELECT won't returns the rows that aren't yet committed by Client 1. Thanks ...

How to implement nested SQL transactions with ADO.NET?

I need to implement nested transactions in .NET using ADO.NET. The situation is as follows: --> Start Process (Begin Transaction) --> Do DB things --> Begin Transaction for step 1 --> Step 1 --> Commit transaction for step 1 --> Begin transaction for step 2 --> Step 2 --> Rollback transaction for s...

Getting account 'locked' status in SQL Server

I want to unlock one account in SQL Server. Before unlocking I have to check whether that account is locked or not. I want to unlock only if the account is locked. Is there any SQL query or stored procedure to get the "Locked" status of SQL user? ...

Split string with delimiter in sql server

I'm having a coloumn name with varchar field that holds some folder path like "C:\Program Files\Internet Explorer\en-US" .I need to update the root folder name(Program files to profilesNew).Can anyone please help. I tried with a query declare @val as varchar(100) set @val='C:\Program Files\Internet Explorer\en-US' select substring(@va...

Variable as numeric sent to stored procedure (SQL Server 2005)

I see that with SQL Server 2005 you can pass a parameter as numeric e.g. create procedure dbo.TestSP @Param1 numeric as But what does this equate to? E.g. Numeric(10,0), Numeric(9,2), etc? We have some Developers here who are using this instead of the correct definition for the field that this parameter is going to be used agains...

Backup SQL Server using ASP.NET

I have virtual hosting with SQL Server. I don't have physical access to SQL Server. I want to make backup and download it. How can I do it from asp.net page? ...

What sql server isolation level should I choose to prevent concurrent reads?

I have the following transaction: SQL inserts a 1 new record into a table called tbl_document SQL deletes all records matching a criteria in another table called tbl_attachment SQL inserts multiple records into the tbl_attachment Until this transaction finishes, I don't want others users to be aware of the (1) new records in tbl_docu...

Using Parameter Values In SQL Statement

I am trying to write a database script (SQL Server 2008) which will copy information from database tables on one server to corresponding tables in another database on a different server. I have read that the correct way to do this is to use a sql statement in a format similar to the following: INSERT INTO <linked_server>.<database>.<ow...

Are there any differences between SQL Server and MySQL when it comes to preventing SQL injection?

I am used to developing in PHP/MySQL and have no experience developing with SQL Server. I've skimmed over the PHP MSSQL documentation and it looks similar to MySQLi in some of the methods I read about. For example, with MySQL I utilize the function mysql_real_excape_string(). Is there a similar function with PHP/SQL Server? What step...

SQL Server 2008 Problem with SCOPE_IDENTITY()

My code does not update the thread field. It is null. Anyone have any ideas? INSERT INTO [Messages]([Sender], [Receiver], [Job_Number], [Subject], [MessageText], [DateSent]) VALUES(@Sender, @Receiver, @Job_Number, @Subject, @MessageText, @DateSent) SET @ThreadID = SCOPE_IDENTITY() UPDATE [Messages] SET Thread = @ThreadID WHERE Messag...

Is this sufficient to prevent query injection while using SQL Server?

Hi, I have recently taken on a project in which I need to integrate with PHP/SQL Server. I am looking for the quickest and easiest function to prevent SQL injection on SQL Server as I prefer MySQL and do not anticipate many more SQL Server related projects. Is this function sufficient? $someVal = mssql_escape($_POST['someVal']); $que...

PERSISTENCE LOB WITH JPA

Hi, Folks. I have this problem using JBOSS, EJB3 and MSSQL Express . i'm trying to persist an entity with an Blob attribute which was converted into a byte[], apparently it create the entity perfectly, no error was logged at jboss's console. but when i check into database the column is null. i already checked the Object to byte[] method ...