sql-server

Access database - links to SQL Server and Oracle

The application part of my database is in Access 2003, and I use tables that are linked from SQL server. Now, I have some tables that I have to link from an Oracle database. I link them through and ODBC connection and it works fine. Is it possible to link that Oracle link in SQL and then link that table as it is already linked in Acces...

SQL Azure and support for CTE syntax?

Does anyone know if SQL Azure supports CTE syntax? Specifically; WITH, OVER, ROW_NUMBER(), PARTITION BY ...

Convert XML to rows

Let's say i've got xml stored in a database. It contains a list of contacts, like so: <Person> <Name>Irwin</Name> <Address>Home, In a place</Address> <Contact type="mobile">7771234</Contact> <Contact type="home">6311234</Contact> <Contact type="work">6352234</Contact> <Contact type="fax">6352238</Contact> </Person> It's stored ...

Using SqlDataAdapter to insert a row

Hello all, I want to insert a row into the Database using SqlDataAdapter. I've 2 tables (Custormers & Orders) in CustomerOrders database and has more than thousand records. I want to create a GUI (TextBoxes) for adding new customer & orders into the Database to their respective tables. How should I do it? I guess the method that is...

Invalid object name '@ImageIDsToDelete'

What is wrong with the following ? DECLARE @ImageIDsToDelete TABLE ( xID INT, ImageID NVARCHAR(500)) INSERT INTO [@ImageIDsToDelete] (xID, ImageID) SELECT 1,'x' ...

Group Similar records Sql Server 2008

Hi All, I will be writing a query to achieve something like below, please help me TableName: Application AppId (PK,int) AppType (bit) 1 0 2 0 3 0 4 0 5 1 6 0 7 0 8 0 9 1 10 1 11 0 12...

SPROC to arrange results alphabetically, except top two results?

I've got a UNIONed query which returns: ReceiptFolderID FolderParentID FolderTypeID FolderType FolderName FolderDescription ReceiptCount --------------- -------------- ------------ --------------------------------------------...

SQL: "Write Protect" row of data possible?

May be a stupid questions but can I protect a row of data in a SQL Server database from being deleted or updated without setting user permissions? This is for a default row of data that can be referenced for its default values? Thanks ...

Get XML schema from database schema (SQL Server 2008 diagram)

Get XML schema from database schema (SQL Server 2008 diagram) I am using SQL Server 2008. Is their is a way to do this in the SQL studio enterprise manager? Rather than write code or use an external tool ...

Inserting an [Order] and [OrderItems] in LINQ

I'm quite new to LINQ and was wondering what was the best design for inserting an [Order], subsequently getting the [Order].[ID] and using this to save some [OrderItems]. The ID column of the [Order] table is an Identity column. I want to try and prevent calling db.SubmitChanges(), getting the newly inserted Order ID and then having ...

SQL Server 2005 - Check for Null DateTime Value

Hello, I'm trying to count the number of records that have a null DateTime value. However, for some reason, my attempts have failed. I have tried the following two queries without any luck: SELECT COUNT(BirthDate) FROM Person p WHERE p.BirthDate IS NULL and SELECT COUNT(BirthDate) FROM Person p WHERE p.BirthDate = NULL What...

How do I compare two columns for equality in SQL Server?

I have two columns that are joined together on certain criteria, but I would also like to check two see if two other columns are identical and then return a bit field if they are. Is there a simpler solution than using CASE WHEN? Ideally I could just use: SELECT Column1 = Column2 AS MyDesiredResult FROM Table1 INNER JOIN Tab...

Various Moving Annual Totals in an SSAS Cube

This is how I am creating my moving totals as columns in my cube: MATTY (Moving Annual Total This Year) SUM ( { [Time Period].[Month].CURRENTMEMBER.Lag(12) : [Time Period].[Month].CURRENTMEMBER }, [Measures].[MeasureColumnName]) MATLY (Moving Annual Total Last Year) SUM ( { [Time Period].[Month].CURRENTMEMBER.Lag(24) : [Time Period]...

nHibernate order by N with SQL Server

With a SQL Query I can order by N, where N is a column index. For example SELECT name, salary FROM employee ORDER BY 2; How can I do this with nHibernate? ...

Sql Query First, Next, Last Rows in a Set

I have two tables that I am trying to join together multiple times. The Parent table is called Jobs, and the child table is called Routings. A Job can have 1 or more Routings. I need my output to contain one record for each job, joined with three separate joins to the Routings table. One join is for Current data (the first null date ...

SQL Server 2005 - Nested recursive query :(

I have a query that I need to execute that I do not know how to structure. I have a table called Employees. I have another table called Company. There is a third table called Files. As you can imagine, a Company has Employees, and Employees have Files. I need to list out all of the Employees in my database. The challenge is, I need to ...

How do I generate a primary key using SSIS?

I'm mucking about with SSIS and can't figure out how to generate a primary key? I have a very simple SSIS Data Flow: Excel File Source -> Character Map -> ADO.NET Destination The Excel file has the following structure: Field1 The destination table has the following structure: ID - UniqueIdentifier (GUID) Field1 There's no probl...

Get all non-clustered indexes

Does anyone know of a good script to get all the non-clustered indexes for SQL Server 2005? ...

Question on schemas and security

I need to set some users up to be able to create stored procedures with READ access only. Also, in production they cannot have SELECT, only EXECUTE on the procs they created. In development they would have SELECT so they could create their procedures. I've set up a schema called Reports. The owner of that schema is a login - Report_A...

How to know where AS keyword should be used ?

Hi everyone, There is a AS keyword in TSQL but in what situations I should use it ? For example : Create View StatisticalData AS Select * from People We used AS keyword in this statement but when creating tables we don't use it , I mean I am kinda confused. Could you please tell me, in what kinda position I should use AS. I mean it i...