sql-server

SQL Server: Inline Table-Value UDF vs. Inline View

I'm working with a medical-record system that stores data in a construct that resembles a spreadsheet--date/time in column headers, measurements (e.g. physician name, Rh, blood type) in first column of each row, and a value in the intersecting cell. Reports that are based on this construct often require 10 or more of these measures to b...

SQL IsNumeric(), shouldn't it return a bit?

I'm just curious to know why SQL IsNumeric() returns int instead of bit? Seems like it should return a bit. ...

How to mimick Oracle Materialized Views on MS SQL Server?

Application connected to MS SQL Server will create views where a single row result is an analysis including aggregations of 1-10k records. The applicable criteria across the resulting view will have dozens to tens of thousands of results. The view+criteria will then be ordered by some column (user specified) in the view which are most li...

How do SQL Server View Indexes work under the hood?

How do SQL Server View Indexes work under the hood? I've read this TechNet article but it doesn't explain how a view index actually works. Can anyone explain this to me? Note: I'm not sure if this should have gone on SF. If it should, just move it over there. ...

How do I use my login rather that my machine name with Windows Authentication to a SQL Server under Web Setup?

I've got a Web Setup project installing a web app. In a Custom Action, I'm executing a SQL script to build a database. Simple, mostly MS sample code. Works fine. private void ExecuteSql(string serverName, string dbName, string Sql) { System.Data.SqlClient.SqlConnection masterConnection = new System.Data.SqlClient.SqlConnection();...

linked-server sql - access Problem

Hi, I have a SQL server 2000 and an Access database mdb connected by Linked server on the other hand I have a program in c # that updates data in a SQL table (Users) based data base access. When running my program returns the following error message: OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. Authentication failed. [...

SQL Aggregation for a smaller result set

I have a database for which I need to aggregate records into another smaller set. This result set should contain the difference between maximum and minumum of specific columns of the original records where they add up to certain SUM, a closed interval constant C. The constant C determines how the original records are aggregated and no ...

SQL Server 2008 Copy Database Wizard: Fail

I am trying to use the SQL Server 2008 Copy Database Wizard to copy a SQL Server 2008 database. I am using the SQL Management Object method. The database contains a full-text index. I have set the 'Server - Properties - Advanced - Full-Text Upgrade Option' to Reset. However, the copy fails with the following error: ERROR : errorCod...

TSQL Generate 5 character length string, all digits [0-9] that doesn't already exist in database...

What's the best way to do this? I need to generate a 5 digit length string where all the characters are numeric. However, I need to be able to do this 'x' amount of times (user variable) and store this random strings in a database. Furthermore, I can't generate the same string twice. Old strings will be removed after 6 months. Pseud...

Grouping by day from 2 tables

I have 2 tables: "orders" and "visits". in the orders table i'm saving some details about the order including "userIP" and "orderDate". in the visits table i'm saving details everytime a user visiting my web page including "userIP" and "visitDate". i'm using ASP.NET and SQL SERVER 2005. i want to create a statistic table whitin i save t...

SQL Server 2008 - Add Windows Account After Deleting Default User

This is rather embarrassing, but I accidentally deleted my Windows account from the list of SQL Server 2008 users and I cannot for the life of me figure out how to re-add myself now that I don't have login privileges. The server is running on my machine and the only other Windows users with access are IUSR, NETWORK SERVICE and SYSTEM. ...

Can I avoid rewriting a table expression in an update?

Suppose you're updating a table that is the result of an expression, like so UPDATE OPENQUERY( server, 'SELECT a from b' ) SET rem.a = loc.a FROM OPENQUERY( server, 'SELECT a from b' ) rem ,local_table loc WHERE rem.id = loc.id Will that OPENQUERY be executed once, or twice? I believe the same would apply to any kind of u...

How do I rename a table in SQL Server Compact Edition?

I've designed my SQL CE tables using the built-in designer in VS2008. I chose the wrong names for a couple. I am now completely stuck trying to find a way to rename them. I am refusing to believe that such a feature could have been "forgotten". How do I rename an existing table using the VS2008 designer, or a free stand-alone app? ...

SQL Server: Compare Index Performance

How can I compare the performance of an Index on a table using the Query Analyzer? I would like to run the same query through the Estimated Execution Plan twice, once using the index and once without, and have a good comparison of the table scans/index scans that are generated. I have tried CREATE INDEX..., SELECT..., DROP INDEX..., SE...

Delete column in SQL Server after a period from creation

I am working with sensitive/private files stored in SQL Server as VarBinary(MAX). Is there a way to tell the database or nHibernate to nullify the column after a period of time after its creation. ...

Database Design for Document Library

We are attempting to built the Document Library (File Management) as apart of our core apps. It starts with simple one obviously. I need a feed back regarding the database design for this particular module. Initial Design: File table: FileID FileGUID TenantID FileName FileDescription FileImage FileSize FileExtension ContentType Crea...

SQL Server query to group sequential date data

I have got a bit of 'brain fade' going on this afternoon, so if anyone can help with this mssql query it would be fantastic. I have a table called 'seasons' with three columns (there are more but not relevant to the example): seasonId, date, tariffId SeasonId is a unique key. A date can only have one tariffid, but a tariffId can have m...

How can I conditionally update a text/ntext field in SQL?

In a stored procedure I'm trying to conditionally update a field (like the 2nd line in the SQL statement below) UPDATE [some_stuff] SET last_update = CASE WHEN val = @NewVal THEN last_update ELSE GETDATE() END, val = @NewVal ...but for a text/ntext field. What's the most efficient way to go about doing that? Does it have to be a s...

Database trigger is recurising :( How to prevent this?

Hi folks, I've got the following trigger on a table for a SQL 2008 database. It's recursing .. so i need to stop it. After I insert or update a record, I'm trying to then update a single field on that table. Simple. Here's the trigger :( ALTER TRIGGER [dbo].[tblMediaAfterInsertOrUpdate] ON [dbo].[tblMedia] BEFORE INSERT, UPDA...

how to find SP Reference

I want to know whether one SP is referenced anywhere. Currently I am checking using SP_DEPENDS. Is there any other way to check this...? ...