tsql

SQL Server - Storing multiple decimal values in a column?

I know storing multiple values in a column. Not a good idea. It violates first normal form --- which states NO multi valued attributes. Normalize period... I am using SQL Server 2005 I have a table that require to store lower limit and uppper limit for a measurement, think of it as a minimum and maximum speed limit... only problem is ...

SQL Split function that handles string with delimeter appearing between text qualifiers?

There are several SQL split functions, from loop driven, to using xml commands, and even using a numbers table. I haven't found one that supports text qualifiers. Using the example string below, I would like to split on ",", but not when it appears between double or single quotes. Example data: [email protected], "Sally \"Heat\" Jo...

TSQL SQL 2000 stored proc cursor

Hi All, I'm new to this board. I have been driving myself crazy trying to find the answer to my problem. I created some TSQL code that executes some dynamic SQL in a cursor within a stored proc. The cursor fetches some data from table x, builds a query based data retrieved in table x, runs the query, and returns data. Works like a charm...

SSMS Ctrl+Tab Page Thumbnail Preview Add-on?

Hey Now, Is there a SQL Server Management studio add-on/plug-in that will enhance the tab switching dialog box when Ctrl+Tab is used to switch tabs to provide a thumbnail image of the tab? When we use Ctrl+Tab to switch tabs we see the list of tabs open. When we switch tabs in Visual Studio we get a small thumb nail preview screen of t...

Passing delimited string to stored procedure to search database

How can i pass a string delimited by space or comma to stored procedure and filter result? I'm trying to do something like - Parameter Value -------------------------- @keywords key1 key2 key3 Then is stored procedure i want to first find all records with first or last name like key1 filter step 1 with first or last name...

How does ANSI_NULLS work in TSQL?

SET ANSI_NULLS OFF seems to give different results in TSQL depending on whether you're comparing a field from a table or a value. Can anyone help me understand why the last 2 of my queries give no results? I'm not looking for a solution, just an explanation. select 1 as 'Col' into #a select NULL as 'Col' into #b --This query gives resu...

SQL Duplicates Issue SQL SERVER 2000

I have two tables : Product and ProductRateDetail. The parent table is Product. I have duplicate records in the product table which need to be unique. There are entries in the ProductRateDetail table which correspond to duplicate records in the product table. Somehow I need to update the ProductRateDetail table to match the original (...

Parse JSON in TSQL

Is it possible to parse JSON in TSQL? I dont mean to create a JSON string, i mean to parse a json string passed in as a parameter. ...

Creating a trigger that manipultes a field in SQL Server

Guys, I have a table called tblNames and one of my fields in this table is called 'UpFileName'. Is it possible to create an insert trigger that would automatically replace all '%20' in the UpFileName field to underscores '_'? I'm using SQL Server 2005. ...

Use SQL to clone data in two tables that have a 1-1 relationship with each other

Using MS SQL 2005, Table 1 ID | T1Value | T2ID | GroupID ---------------------------------- 1 | a | 10 | 1 2 | b | 11 | 1 3 | c | 12 | 1 4 | a | 22 | 2 Table 2 ID | T2Value ---------------- 10 | H 11 | J 12 | K 22 | H I want to clone the dat...

SQL Server 2005 Convert Ascii to Unicode (UTF-8 -> nvarchar)

I have data in an nvarchar field with data in ascii format: "Zard Frères Guesta" How do I convert it to a readable(unicode) format in t-sql? ...

Tell SQL Server the error is "handled" in try...catch

I'd like to indicate to SQL Server 2005, in my BEGIN CATCH...END CATCH block that the error is "handled"... That is, clear the error. Is that possible? Consider this: begin transaction begin try begin transaction select cast('X' as bit) commit transaction end try begin catch rollback transaction select...

Working by group by for grouping data into string format

I have a table that contains some data given below. It uses a tree like structure i.e. Department SubD1, SubD2 ..... PreSubD1, PreSubD1... PreSubD2, PreSubD2... pk_map_id preferences ImmediateParent Department_Id -------------------- ---------------...

Optimising a query for Top 5% of users

On my website, there exists a group of 'power users' who are fantastic and adding lots of content on to my site. However, their prolific activities has led to their profile pages slowing down a lot. For 95% of the other users, the SPROC that is returning the data is very quick. It's only for these group of power users, the very same SP...

SQL Split function.

Hi guys, I'm looking for a way to do this ... SELECT FirstName, LastName, Split(AddressBlock, ' ', 1), Split(AddressBlock, ' ', 2), PostCode FROM Contacts The arguments I want to pass are ... The address The separator (current situation requires 2 spaces but this might be a comma or a space followed by a comma) or something els...

Select statement always execute/select columns in order?

Does all the columns in select statement gets selected one after another as listed? Declare @X, @Y SELECT @X = ColumnA*.25 + ColumnB*2.5, @Y = ColumnA*.5 + ColumnC*1.33, TOTAL = @X + @Y FROM SomeTable Is the above query safe to use? Will total always be selected after @X and @Y are calculated? ...

Problem with nvarchar data with XML in SQL server 2005

Create table testxml (xmldata xml) declare @var nvarchar(max) set @var = N'الوفاق الوطني المخ' insert into testxml select @var After inserting , i am getting data from table like select * from testxml --------------------- ???????? Can you provide me the solution? ...

T-SQL Better way to determine max of date (accounting for nulls)

I am comparing two dates and trying to determine the max of the two dates. A null date would be considered less than a valid date. I am using the following case statement, which works - but feels very inefficient and clunky. Is there a better way? update @TEMP_EARNED set nextearn = case when lastoccurrence is null and lastearned is null...

How to Compare two strings using a if in a stored procedure in sql server 2008?

I want to do something like this: declare @temp as varchar set @temp='Measure' if(@temp == 'Measure') Select Measure from Measuretable else Select OtherMeasure from Measuretable ...

Insert a Join Statement - (Insert Data to Multiple Tables) - C#/SQL/T-SQL/.NET

I have a Winform that has fields need to be filled by a user. All the fields doesn't belong to one table, the data will go to Customer table and CustomerPhone table, so i decided to do multiple inserts. I will insert appropriate data to CustomerPhone first then Insert the rest data to Customer table. Is it possible to Join an Insert OR ...