tsql

Shredding XML Data into Tables

I have an issue where I must shred multiple xml datasets from multiple providers into a single set of tables by mapping various elements in the sources to my own tables. I can do this just fine when I am gathering the top level information, but some of my information is in a collection, such as the categories. My first step is just to ...

Concatenate multiple xml columntype rows in SQL

I have an online form, whereby each entry adds the data as xml to an xml column in SQL. ApplicationID(uniqueidentifier) | DateModified | ApplicationForm(XML) What I need to do is perform a select query that will grab all the ApplicationForm xml values, and concatenate them together to form one result, e.g. Row1: <ApplicationForm type...

SQL Server remove milliseconds from datetime

select * from table where date > '2010-07-20 03:21:52' which I would expect to not give me any results... EXCEPT I'm getting a record with a datetime of 2010-07-20 03:21:52.577 how can I make the query ignore milliseconds? ...

SQL Server cast to text datatype

Can someone help me with SQL Server CAST to text datatype? I'm trying to get the long text to display using the CAST function, but it wont work if I am retrieving from more than 1 table. Perhaps I've created the statement incorrectly. $from = 'RealEstate AS RE, Models AS M, Catalogue AS C'; $select = 'CAST(RE.Details AS TEXT) AS RE.Det...

Generating number between these start and end fields

Hi there I have 3 column (ID, Start and End) in TSQL. ID; Start; END 1; 1; 5; 2; 10; 15; So it will generate number like: 1, 1 1, 2 1, 3 1, 4 1, 5 2, 10 2, 11 2, 12 2, 13 2, 14 2, 15 Again all I can think of is cursor but is there any better way? ...

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...

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...

SQL Timeout and indices

Changing and finding stuff in a database containing a few dozen tables with around half a million rows in the big ones I'm running into timeouts quite often. Some of these timeouts I don't understand. For example I got this table: CREATE TABLE dbo.[VPI_APO] ( [Key] bigint IDENTITY(1,1) NOT NULL CONSTRAINT [PK_VPI_APO] PRIMARY KEY, ...

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)....

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? ...

Generate rows with index between two numbers

I have a single table varchar, int, int like this: OS MinSP MaxSP -- ----- ----- 2000 4 4 XP 2 3 Vista 0 2 7 0 1 What I want is a query which will generate a list of values like this: 2000 SP4 XP SP2 XP SP3 Vista Vista SP1 Vista SP2 7 7 S...

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...

varbinary to string on SQL Server

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

Is it possible to tell SSMS not to check if a column exists in a t-sql script?

Hi, I tried to google it, but din't find a way I have a t-sql script that adds a new column to a table, then fills that columns with values depending on some other columns in the same table and finally removes some columns. This all works fine. The problem occures when I want to run the script again. I have a if clause that checks if ...

SQL Server 2K - Insert explicit value for timestamp column?

Hey all, I'm curently working on a project where I need to transfer data (with some minor transformations) from one database to another. Everything was going just fine when I hit my first Timestamp column... It seems SQL Server doesn't want me to use explicit values for this type of column and it, instead, wants to generate its own. ...

SQL Server dbo and schema

Hi, I've stumbled across some odd T-SQL code in SQL Server 2005, which I'm trying to understand how it could work. If there are two tables called tblScenario in two separate schemas, one is in Cache schema and the other is in Dimension schema. What would we expect to find when we query SELECT * FROM dbo.tblScenario? How does dbo map ...

t-sql stored procedure create scripts

Hi I have a bunch of stored procedure names. I want to export the create script for each of the stored procedure. What is the best way to do it? Right now I am manually selecting the stored proc in SSMS and selecting "Script stored procedure as -> Drop and Create to". This seems tedious. I am hoping there is a better way to deal with ...

SQL: Best approach to Select and Insert from multiple tables

What do you guys think would be the best approach here? I have about 30 SQL tables that is basically referenced by a [lookup] table. I have to do an insert in another table [FinalTable] for each row in the [lookup] table. Now the [lookup] table looks something like this. ID, Zipcode, tableID 1, 60453, 1 2, 90210, 1 3, 60453, ...

SQL Server: Using a case statement to see if a date is NULL and if it is returning ' '

I have a column in my select statement that looks like this: SELECT CASE WHEN fu.SentOutDate IS NULL THEN '' ELSE fu.SentOutDate END This returns 1900-01-01 00:00:00.000 for the ones that would otherwise be NULL I know this because when I put in just fu.SentOutDate it comes up as NULL Why does this happen and how can I just get it t...