sql-server

Synchronizing non-DB SQL Server objects

There are a number of tools available for synchronizing Tables, Indexes, Views, Stored Procedures and objects within a database. (We love RedGate here, and throw a lot of money their way). However, I'm having a very difficult time finding tools that will help with Jobs, Logins and Linked Servers. Do these things exist? Am I missing som...

Type "Time" in SQL Server and C#

Is there any way that I can create the type time in C# to be compatible with the type time of the SQL server? ...

Converting nvarchar(4000) to nvarchar(max)

Hi! We have a few tables in our SQL Server (2005 & 2008) database with columns defined as nvarchar(4000). We sometimes need to be able to store more data than that and consider to use nvarchar(max) instead. Now to the questions. Are there any performance implications we should know of? Is it safe to use "alter table" to do the actual...

distance between two points across land using sql server

I am looking to calculate the shortest distance between two points inside SQL Server 2008 taking into account land mass only. I have used the geography data type along with STDistance() to work out point x distance to point y as the crow flies, however this sometimes crosses the sea which i am trying to avoid. I have also created a p...

Why is my SQL Server query failing?

connect(); $arr = mssql_fetch_assoc(mssql_query("SELECT Applications.ProductName, Applications.ProductVersion, Applications.ProductSize, Applications.Description, Applications.ProductKey, Applications.ProductKeyID, Applications.AutomatedInstaller, Applications.AutomatedInstallerName, Applications.ISO, A...

Complex SQL design, help/advice needed

Hi, i have few questions for SQL gurus in here ... Briefly this is ads management system where user can define campaigns for different countries, categories, languages. I have few questions in mind so help me with what you can. Generally i'm using ASP.NET and i want to cache all result set of certain user once he asks for statistics for...

Export SQL Binary/BLOB Data?

Recently a software application we utilize upgraded from ASP to ASP.NET. In the process they abandoned the old web-based product and rewrote the entire UI, using new DB tables. The old DB tables still exist in the database and contain legacy files in binary or blob formats. I'm wondering if there is an easy way to export all these legacy...

Executing a query on csv data stored in an ntext column

Say that the raw text of CSV exports and an associated timestamps are stored in a database, where one record is equivalent to one export. Does anyone have a way to execute a query on the CSV file stored in that field without creating a second connection to the database or exporting the data to a file and then reopening it using the csv ...

Does SQL Server CE support synchronization of Spatial Data type?

Does Sql Server support replication to SQL Server CE? In the documentation, SQL server CE seems to be not supporting the st_geometry type. ...

SQL - Two foreign keys that have a dependency between them

The current structure is as follows: Table RowType: RowTypeID Table RowSubType: RowSubTypeID FK_RowTypeID Table ColumnDef: FK_RowTypeID FK_RowSubTypeID (nullable) In short, I'm mapping column definitions to rows. In some cases, those rows have subtype(s), which will have column definitions sp...

Optimizing ROW_NUMBER() in SQL Server

We have a number of machines which record data into a database at sporadic intervals. For each record, I'd like to obtain the time period between this recording and the previous recording. I can do this using ROW_NUMBER as follows: WITH TempTable AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY Machine_ID ORDER BY Date_Time) AS Orde...

Selecting a Function Value Shows nvarchar(4000) on an Index

I have a view that I'm trying to setup an Index for. One of the select columns for the view executes a user-defined function that has a return value of varchar(250). However, when I try to setup an Index on that column, I see a size of nvarchar(4000). Why is that and will that cause a problem if I continue to setup my index? ...

IF/ELSE makes stored procedure not return a result set

I have a stored procedure that needs to return something from one of two databases: IF @x = 1 SELECT y FROM Table_A ELSE IF @x = 2 SELECT y FROM Table_B Either SELECT alone will return what I want, but adding the IF/ELSE makes it stop returning anything. I tried: IF @x = 1 RETURN SELECT y FROM Table_A ELSE IF @x = 2 R...

Displaying Query Results Horizontally

I am wondering if it is possible to take the results of a query and return them as a CSV string instead of as a column of cells. Basically, we have a table called Customers, and we have a table called CustomerTypeLines, and each Customer can have multiple CustomerTypeLines. When I run a query against it, I run into problems when I want ...

SQL Server 2005, wide indexes, computed columns, and sargable queries

In my database, assume we have a table defined as follows: CREATE TABLE [Chemical]( [ChemicalId] int NOT NULL IDENTITY(1,1) PRIMARY KEY, [Name] nvarchar(max) NOT NULL, [Description] nvarchar(max) NULL ) The value for Name can be very large, so we must use nvarchar(max). Unfortunately, we want to create an index on this col...

Storing windows login in SQL Server table

Are there any best practices for storing Windows logins in SQL server tables(e.g. AddUser field for an audit table)? I have seen tables using sysname, varchar(255) etc. p.s. Apologies in advance if this has already been answered. I couldn't find or formulate the right query to look this up. ...

Is there a decent technique for SSIS Derived Column date formatting?

I just had to write the most redonkulous expression in an SSIS Derived Column to get dates formatted like "01-JAN-2010".  It lookes like this:        There's got to be a better way... isn't there? ...

SQLce Select query problem

Wrote a Truck show Contest voting app, financial etc using sqlite. decided to write backup app for show day using ce 3.5. Created db moved to data directory, created tables configured dgridviews all is well. Entered some test data started management studio 08 ran select query against table and got null returns. Started app from vs studio...

Which fieldtype is best for storing PRICE values?

Hi there I am wondering whats the best "price field" in SQL Server for a shoplike structure? Looking at this overview: http://www.teratrax.com/sql_guide/data_types/sql_server_data_types.html We have data types called money, smallmoney, then we have decimal/numeric and lastly float and real Name, memory/disk-usage and value ranges: M...

SQL Server instead of MYSQL in WAMP

Hi, We have an application which uses WAMP server. Now, there is a new requirement from a customer who wants to use MS SQL Server instead of MySQL. How easy is it to port to SQL Server from MySQL. Also it has to retain this configuration. Apache->PHP->SQL Server on windows. How can I connect from Apache to SQL Server. Hope PHP works well...