sql-server

Can I use a SQL Server identity column to determine the inserted order of rows?

I need to be able to determine the order which rows have been inserted into a table (there are no updates). Can I use an identity column to do this? I know that there may be gaps, but are the values guaranteed to be increasing by insertion order? ...

Get records ordered alphabetically starting by a certain letter in Sql Server

In SQLSERVER/MSSQL, here's the problem: SELECT * from [Translation Color] order by [Language Code] I want records ordered in alphabetical order starting by the 'I' letter. Example of result: 'Ioren' 'Iumen' 'Tart' 'Arfen' 'Coldry' I don't want to use union or more sql statements.. just try to catch it with an order by special claus...

Restore sql doesnt fire

Hi Im trying restore database from backup dynamically with application code simple sql command for restore con.execute("RESTORE FILELISTONLY FROM DISK='c:\old.bak' " & vbcrlf &_ "RESTORE DATABASE newdb " & vbcrlf &_ "FROM DISK='c:\old.bak' " & vbcrlf &_ "WITH MOVE 'newdb' TO 'c:\newdb.mdf', " & vbcrlf &_ ...

how to write sql query? for ms sql server

I need to write a sql query that adds one column from one database (DB1) to another column and the sum is save in that column in the second database(DB2). where userIds are the same DB1 TableA UserId People DB2 TableB Amount UserId it would be something like this DB2.TableB.Amount = DB2.TableB.Amount + DB1.TableA.People ...

SQL Server Reporting Services(Chart Filters)

Hi!! I would like to pose a question regarding the Chart Filter properties in SSRS. I would like to know why the filter property doesnot work when I try to filter the Last 3 years of data. The condition is that I can't tamper with the database nor can I modify the Columns at tha database level. I need to implement this Filter at SSRS le...

MSSQL Cursor for huge tables cannot allocate space

We are trying to set up a cursor to run through records generated from a join between two 'instances' of the same huge table (more than 150 M records). The following exception message comes out: Could not allocate space for object 'dbo.SORT temporary run storage: 165282123350016' in database 'tempdb' because the 'PRIMARY' filegroup...

Copying SQL Server DB using script

Hi I have to copy a db from a remote server to my local dev machine. What is the best way to do it. Last night i made a script for the remote db using xSQL Object and ran it on the local server. the script gave a bunch of errors. Below is the select @@version output for the 2 servers. is there a reason the script is not working The rem...

Error "Microsoft SQL Native Client error '80040e37'"

After moving my database and web site for another server I got the error Microsoft SQL Native Client error '80040e37'. The problem occurs in a query inside an asp file that do not have schema.tablename, only tablename. But I do not want to include "schema" in all queries right now. All updates were installed and the default schema...

What does it mean by "Non-deterministic User-Defined functions can be used in a deterministic manner"?

According to MSDN SQL BOL (Books Online) page on Deterministic and Nondeterministic Functions, non-deterministic functions can be used "in a deterministic manner" The following functions are not always deterministic, but can be used in indexed views or indexes on computed columns when they are specified in a deterministic manner. ...

Pass Query Result to a csv file and Send it as attachement using SQL Server 2005

I have two tasks and since I am new to it, I need some help/advice from the masters. What I need to do is send the result of q select query to a csv file which can have delimeter as comma or tab and then send this file as an attachement to a particular receipient. Hoping for some great advice ...

Pass Query Results to a csv file and Send it as mail using SQL Server 2005

I have two tasks and since I am new to it, I need some help/advice from the masters. What I need to do is send the result of q select query to a csv file which can have delimeter as comma or tab and then send this file as mail to a particular receipient. Hoping for some great advice ...

Can I store SQL Server sort order in a variable?

I have the following SQL within a stored procedure. Is there a way to remove the IF statement and pass the 'ASC'/'DESC' option as a variable? I know I could do the query a number of different ways, or return a table and sort it externally etc. I would just like to know if I can avoid duplicating the CASE statement. IF @sortOrder = 'Des...

Accessing data from a .gdb file with SQL Server Integration Services (2005 or 2008)

I have number of files in .gdb format, which I believe is associated with Borland interbase. Does anyone know how I would go about extracting data from the using SSIS (2005 or 2008)? Any help very much appreciated. Ed. ...

Installed Service Pack 3 for SQL Server 2005 but it does not show up when selecting @@version

We installed Service Pack 3 for SQL Server 2005 Standard Edition (64-bit). In the Add or Remove Programs menu we have the following entries under Microsoft SQL Server 2005 (64-bit): Service Pack 3 for SQL Server Integration Services 64-bit) ENU (KB955706) Service Pack 3 for SQL Server Notification Services 2005 (64-bit) ENU (KB955706) ...

Truncation error SQL server 2005 Delete/Insert

So I am trying to do a bulk insert with SSIS and continually get: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "String or binary data would be truncated." Even though I already have a data conversion for every column into the exact same type as the table that the rows are getting inserted into. I used a view and the...

How can I select distinct rows when a text field is part of the returned fields in MS SQL Server 2000?

I have a database-driven FAQ that is organised into sections and I am trying to get the section data for only those sections who have a question/answer associated with them. Here is the schema: |---------------------| |----------------------| | Section | | Quest-Ans | |---------------------| |-----...

There is a way to access the "previous row" value in a SELECT statement?

I need to calculate the difference of a column between two lines of a table, there is any way I can do this directly in SQL? I'm using Microsoft SQL Server 2008. I'm looking for something like this: SELECT value - (previous.value) FROM table Imagining that the "previous" variable reference the latest selected row. Of course that with...

Is there a silver bullet to importing XML data into SQL Server 2008 Express?

I've tried the Import/Export wizard, but there is no XML driver under the Data source drop down. Is there a way to import XML data into SQL Express without writing an app to do it explicitly? ...

How can I write a where clause in SQL to filter a DATETIME column by the time of day?

I have data that is timestamped with a DATETIME column and I want to filter it down to the set of records where the DATETIME is between 9:30am and 5:30pm for any day. What's the best way to do this? UPDATE: Changed because I need precision to the minute, not just hour. Sorry about that. ...

Why Is My Inline Table UDF so much slower when I use variable parameters rather than constant parameters?

I have a table-valued, inline UDF. I want to filter the results of that UDF to get one particular value. When I specify the filter using a constant parameter, everything is great and performance is almost instantaneous. When I specify the filter using a variable parameter, it takes a significantly larger chunk of time, on the order of...