sql-server

SQL Script patindex

I think i have some syntax error in my script but can't figure out where. I want to select the Integer that falls between a pair of ( ) begining from the right of a cell? Reason being, there might be another pair of brackets containing characters and what if some records are w/o close brackets for some reason.. e.g. Period | Program...

Select query on a partitioned table

Hi, I have partitioned a table and it has been partitioned according to an account id. ie also rows that have accountid =1 will be in A partition and all rows that have accountid = 2 will be in B partition. so now if i execute a query with where condition accountid =1 sql server will search only in A partition. Suppose if i add anothe...

SSMS Change Scripts & Transaction

Hi all! I'm not an expert on SQL Server/T-SQL/SMSS so please bear with me :) I use the 'Generate change script' feature of SMSS to track database schema changes. This generates files like the following: BEGIN TRANSACTION SET QUOTED_IDENTIFIER ON SET ARITHABORT ON SET NUMERIC_ROUNDABORT OFF SET CONCAT_NULL_YIELDS_NULL ON SET ANSI_NULL...

How to retrieve the table from two different datagrids with some certain constraints?

I have two tables invoices and receipts i have to show the alternate data of invoices and receipts in datagrid; condition is that if Date column in INVOICE table matches with invoice columns in RECEIPTS table then the corresponding row of RECEIPTS table should come after INVOICES table row if there is no match then INVOICES table n...

Asynchronous call of a SQL Server stored procedure in C#

Is it possible to call a SQL Server stored procedure asynchronously via C#? I have a stored procedure which writes a backup of a specific database (this can takes a longer time) and I want to show the progress of the backup process in a windows forms (for this I use http://www.wisesoft.co.uk/articles/tsql_backup_restore_progress.aspx)....

How the cdc retention value can be changed for the cleanup job?

Hi there. I'm implementing a logging feature on a asp.net mvc2 application, that uses SqlServer2008 as a database and Entity Framework as a data model. I enabled CDC feature of SqlServer and it's logging changes well, but I just noticed that some of the old logging data is erased. Does anyone know what's default period CDC keeps recor...

T-Sql function to convert a varchar - in this instance someone's name - from upper to title case?

Does anyone have in their back pocket a function that can achieve this? ...

Invoking SQL Server Service Broker from a web service

I'm looking at doing this, however I'm having difficulty find any code samples of how to do this. Presumably I make the call in the c# code for the provider ?, however what concerns me from a performance point of view is that I will be deserialising XML to objects from the web service and then turning these objects back into XML for serv...

SQL server root Directory

Dear Friend, How can i Retrive Root Directory in SQL Server using SQL Query??? Thanks. ...

Concat Columns with NULL-values

I want to concat two Columns in the TableAdapter Wizard of the VS Dataset-Designer. The problem is that one column has NULL-Values and hence the concatination results in NULL regardless of the value of the other column. I've found out that i must SET CONCAT_NULL_YIELDS_NULL OFF, which is a Database option. How can i change this setting ...

T-SQL DateDiff - partition by "full hours ago", rather than "times minutes turned 00 since"

I have a table with timestamps, and I want to partition this table into hour-long intervals, starting at now and going backwards a couple of hours. I'm unable to get the results I need with the T-SQL DATEDIFF function, since it counts the number of times the minute hand passes 12 between the two dates - I want the number of times them mi...

insert data into several tables - possibly using OUTPUT - sql server 2005

Dear all, I would like to insert data from a file into the table Division of this model which is very much simplified: create table Statements ( Id INT IDENTITY NOT NULL primary key (Id) ) create table Item ( StatementFk INT not null, ItemNameFk INT not null, primary key (StatementFk) ) cr...

How to find rows in SQL that start with the same string (similar rows)?

I have a table with primary keys that look like this: FIRSTKEY~ABC SECONDKEY~DEF FIRSTKEY~DEF I want to write a SELECT statement that strips off the segment following the tilde and returns all rows that are duplicates after the post-tilde segment is gone. That is, SELECT ... Gives me: FIRSTKEY~ABC FIRSTKEY~DEF As "duplicates". ...

varbinary to string on SQL Server

How to convert a column value from varbinary(max) to varchar to read.. ...

Super fuzzy name checking?

I'm working on some stuff for an in-house CRM. The company's current frontend allows for lots of duplicates. I'm trying to stop end-users from putting in the same person because they searched for 'Bill Johnson' and not 'William Johnson.' So the user will put in some information about their new customer and we'll find the similar names (i...

Number of concurrent Sql Server connections

I am creating a .net application, with a Sql Server db engine. I would like my site to be accessed by thousands of users per second. What does the number of connections rely on? How many connection can IIS hold, and Sql Server? ...

SQL Server Express 2005 unicode characters

I'm working with an SQL Server 2005 Express instance. Any attempt (both programatically or by using a table editor (for example VS Server Explorer --> Edit Table Data)) to enter a unicode string results in a sequence of question marks (????). I guess that either SQL Server 2005 Express doesn't support unicode at all or it requires some e...

Incorrect syntax near the keyword 'group' trying to link multiple tables in SQL Server

I am trying to link several tables together in SQL Server. The code below shows how I have linked the tables together so far: select * from profile left join learner l on l.learnerid = profileid left join learner_levels ll on ll.learnerid = l.learnerid left join subjects s on s.subjectid = ll.subjectid left join learner_group lg on lg.l...

Using UPDATE in stored procedure with optional parameters

I have an SP like so (using SQL Server): ALTER PROCEDURE [dbo].[sp_ClientNotes_update] @id uniqueidentifier, @ordering smallint = NULL, @title nvarchar(20) = NULL, @content text = NULL AS BEGIN SET NOCOUNT ON; UPDATE tbl_ClientNotes SET ordering=@ordering, title=@title, content=@content WHERE id=@id END ...

Creating A Script To Replicate A Table And Its Contents?

I know you can create a script to replicate a table using: right click table > script table as > create to > new query editor window But how can I generate a script that contains a bunch of insert commands for each row in the table? Table1 Id1, Row1 Id2, Row2 Id3, Row3 Insert into Table1 values(Row1); Insert into Table1 values(Row2);...