tsql

How to do regex HTML tag replace in SQL Server?

I have a table in SQL Server 2005 with hundreds of rows with HTML content. Some of the content has HTML like: <span class=heading-2>Directions</span> where "Directions" changes depending on page name. I need to change all the <span class=heading-2> and </span> tags to <h2> and </h2> tags. I wrote this query to do content changes in ...

3 tier application pattern suggestion

I have attempted to make my first 3 tier application. In the process I have run into one problem I am yet to find an optimal solution for. Basically all my objects use an IFillable interface which forces the implementation of a sub as follows Public Sub Fill(ByVal Datareader As Data.IDataReader) Implements IFillable.Fill This sub the...

create new table having many to one relationship between other two tables-sql server management studio

Hi, I have two tables, one table has rowguid column and other has auto incremented column but both tables dont have primary key or foreign key. I want to create third table that store the relationship between above two tables. can somebody give me the correct and easiest way to do that. i m new using sql server. please reply me ...

how to enter values in rowguid column?

can anyone please tell me the right way to insert values in the rowguid column of the table? I m using sql server management studio ...

In TSQL (SQL Server), How do I insert multiple rows WITHOUT repeating the "INSERT INTO dbo.Blah" part of the statement?

I know I've done this before years ago, but I can't remember the syntax, and I can't find it anywhere due to pulling up tons of help docs and articles about "bulk imports". Here's what I want to do, but the syntax is not exactly right... please, someone who has done this before, help me out :) INSERT INTO dbo.MyTable (ID, Name) VALUES ...

Adding miliseconds to a datetime in tsql INSERT INTO

I'm doing a INSERT INTO query in order to initialize a new table. The primary key is RFQ_ID and Action_Time How could add 1 milisecond to each Action_Time on new record in order to avoid "Violation of PRIMARY KEY constraint" INSERT INTO QSW_RFQ_Log (RFQ_ID, Action_Time, Quote_ID, Note) SELECT RFQ_ID , GETDATE() AS Action_Time , ...

SQL Server Multiple Joins Are Taxing The CPU

I have a stored procedure on SQL Server 2005. It is pulling from a Table function, and has two joins. When the query is run using a load test it kills the CPU 100% across all 16 cores! I have determined that removing one of the joins makes the query run fine, but both taxes the CPU. Select SKey From dbo.tfnGetLatest(@ID) a le...

Get tree representation from t-sql stored procedure

Hi, I want to get tree representation answer from my t-sql stored procedure. How can I do it ? Does .NET have a predefined types for working with xml-answers from stored procedures ? ...

SQL 2008: Using separate tables for each datatype to return single row

Hi all I thought I'd be flexible this time around and let the users decide what contact information the wish to store in their database. In theory it would look as a single row containing, for instance; name, adress, zipcode, Category X, Listitems A. Example FieldType table defining the datatypes available to a user: FieldTypeID, Fiel...

SELECT TOP N With Two Variables

I have the following example in a SQL table Cust Group Sales A 1 15 A 1 10 A 1 5 A 2 15 A 2 10 A 2 5 B 1 15 B 1 10 B 1 5 B 2 15 B 2 10 B 2 5 What I would like to show is the top 2 products per customer, per group sorted descending by Sales i.e. Cust Group Sales A 1 15 A 1 ...

Getting 'The argument 1 of the xml data type method "modify" must be a string literal' while inserting a attribute in xml

Trying the following code. But getting 'The argument 1 of the xml data type method "modify" must be a string literal' error. searched alot but cant find any solution for this problem SET @Path = '/@ParentNodeName/@NodeName/child::*' SET @x.modify('insert attribute status {sql:variable("@status")} as first into (' + @Pat...

SQL : where vs. on in join

Perhaps a dumb question, but consider these 2 tables : T1 Store Year 01 2009 02 2009 03 2009 01 2010 02 2010 03 2010 T2 Store 02 Why is this INNER JOIN giving me the results I want (filtering the [year] in the ON clause) : select t1.* from t1 inner join t2 on t1.store = t2.store and t1.[year] = '2009'...

Advice on optimzing speed for a Stored Procedure that uses Views

Based on a previous question and with a lot of help from Damir Sudarevic (thanks) I have the following sql code which works great but is very slow. Can anyone suggest how I can speed this up and optimise for speed. I am now using SQL Server Express 2008 (not 2005 as per my original question). What this code does is retrieves paramet...

Getting the 'date' out of a DateTime field in SQL Server

I have a date column where the date is displayed in the format 2009-11-18 10:55:28.370. I just want to get the date (not time) out of that value. How do I do that? ...

T-SQL aggregate function Logical error

Hi Guys, Ok I have a data table containing duplicate Reciept numbers and a transaction value for each record, I need to simply list the total for each unique Reciept number, this is obviously a simple problem but I am missing something. Any help is much appriciated SELECT Gf_Receipt_number AS Reciept, SUM (Gf_Amount) AS Total ...

T-SQL Script to Delete All The Relationships Between A Bunch Of Tables in a Schema and Other Bunch in another Schema?

Guys, I have a set of tables (say Account, Customer) in a schema (say dbo) and I have some other tables (say Order, OrderItem) in another schema (say inventory). There's a relationship between the Order table and the Customer table. I want to delete all the relationships between the tables in the first schema (dbo) and the tables in t...

Inserting "null" (literally) in to a stored procedure parameter.

I'm trying to insert the word "Null" (literally) in to a parameter for a stored procedure. For some reason SqlServer seems to think I mean NULL and not "Null". If I do a check for IF @LastName IS NULL // Test: Do stuff Then it bypasses that because the parameter isn't null. But when I do: INSERT INTO Person (<params>) VALUES (<stuff...

comparing data via a function

I have two sets of data (locations) in separate tables and I need to compare if they match or not. I have a UDF which performs a calculation based upon 5 values from each table. How do I perform a select with a join using this udf? my udf is basically defined by.... ALTER FUNCTION [dbo].[MatchRanking] ( @Latitude FLOAT ...

Why would a t-sql query that was previously working and hasn't been changed, no longer return any rows?

I have run this query successfully multiple times no more than a couple of weeks ago. I have not made a single change to it. It seems unlikely that the back-end data would have changed enough to produce no results. What else could contribute to this? ...

stored procedure vs UDF

I have a select statement and in a couple of the fields, I want to check if an entry for the record exists in another table and if it does, output 1 value and if it doesn't, provide another value. What would be the best way to do it? When would you use a stored procedure and when would you use a UDF? ...