sql-server

When is IS_MEMBER set in Sql Server?

I am trying to get IS_MEMBER working in a UDF in Sql Server 2005. I have a windows group "Domain\TestGroup". I allocate my Login "Domain\Kieran" to it. select SUSER_NAME(); gives "Domain\Kieran" but select IS_MEMBER('Domain\TestGroup'); returns NULL. ...

SQL Server Dynamic Columns Problem

I use a table GadgetData to store the properties of gadgets in my application. There gadgets are basically sort of custom control which have 80% of the properties common like height, width, color, type etc. There are are some set of properties per gadget type that the unique to them. All of this data has to store in database. Currently I...

Equivalent of Oracle's RowID in SQL Server

What's the equivalent of Oracle's RowID in SQL Server? ...

sql server data fields nvchar(x) or nvarchar(max)

Is it good practice to set all text fields to nvarchar(MAX)? if im not sure what the size of the field will be will it take up extra space ...

Transact-SQL: insert into xyz ( select * from abc )

Hi, i want to realize a construct in MS SQL that would look like this in Oracles PL/SQL: declare asdf number; begin for r in (select * from xyz) loop insert into abc (column1, column2, column3) values (r.asdf, r.vcxvc, r.dffgdfg) returning id into asdf; update xyz set column10 = asdf where ID = r.ID; end loop; end; Any i...

How to merge two databases in SQL Server?

Both databases have the same schema, but they may experience conflict with primary key in some tables. So I want them to just ignore the duplicate rows, and continue merging further. ...

Java/MSSQL: java.sql.SQLException Invalid object name 'TableName'.

I'm trying to move a java application from an old server to a new server. The application runs on Tomcat, uses Microsoft SQL Server as the backend DB, and used a system DSN defined in Data Sources (ODBC) to decide where to connect to. The old server used Windows 2000/SQL server 2000, the new server uses Windows 2003/SQL Server 2005. T...

SqlServer to Excel export with OPENROWSET

All, I am successfully exporting to excel with the following statement: insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\template.xls;', 'SELECT * FROM [SheetName$]') select * from myTable Is there any standard way to use this template specifying a new name for the excel sheet so that the template never get...

How can I minimize the data in a SQL replication

I want to replicate data from a boat offshore to an onshore site. The connection is some times via a sattelite link and can be slow and have a high latency. Latency in our application is important, the people on-shore should have the data as soon as possible. There is one table being replicated, consisting of an id, datetime and some...

SSIS - Saving to Office 2007 Format

I'm trying to save an excel spreadhseet from SQL Server Integration Services 2005. Unfortunatly I only seem to be able to save in 2003 format but I want to be able to save in 2007 format. Is there wa way to do this? ...

Avoiding SQL injection without parameters

We are having another discussion here at work about using parametrized sql queries in our code. We have two sides in the discussion: Me and some others that say we should always use parameters to safeguard against sql injections and the other guys that don't think it is necessary. Instead they want to replace single apostrophes with two ...

Slow inital query when using FreeTextTable in SQL Server 2005

The following FreeTextTable query takes > 10 seconds on the first request, but about a second for subsequent requests: SELECT [Key], [Rank] INTO #matches FROM FREETEXTTABLE(Book, [Description], @searchWord) After approx. 10 minutes of inactivity the next request will once again take > 10 seconds. This seems like the freetext cache is ...

Is it possible to calculate MD5 hash directly in T-SQL language?

Hi all, I need to hash (MD5) all the password in our Sql Server 2000 database. I can easily generate a C#/VB.NET program to convert (hash) all the passwords, but I was wondering (more for my education than for a real compelling need) if it was possible to calculate MD5 hash directly in T-SQL. Thanks to anyone who will answer. ...

Sql threw error when executed under transaction

Hi All, I am trying to execute following syntax under transaction but it throws error:- this is the script that I am executing under transaction:- IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) -- full text search is installed. Run the necessary procedures BEGIN declare @dbName nvarchar(128) select @dbName = DB_Name() ...

SQL Optimization Query

The below MSSQL2005 query is very slow. I feel like their ought to be a way to speed it up, but am unsure how. Note that I editted the inner join to use select statements to make it more obvious (to people reading this question) what is going on, though this has no impact on speed (probably the Execution plan is the same either way). ...

SQL Select Statement For Calculating A Running Average Column

I am trying to have a running average column in the SELECT statement based on a column from the n previous rows in the same SELECT statement. The average I need is based on the n previous rows in the resultset. Let me explain Id Number Average 1 1 NULL 2 3 NULL 3 2 ...

Develop Locally on SQL Server 2005 then Deploying to Shared Hosting

What is the best way to develop on SQL Server 2005 machine locally while you get your database design and application design smoothed out and then deploy to a shared host? In the MySQL / phpMyAdmin world you have an option to export the table as the DDL Statement with the data represented as a bunch of inserts following the DDL. Using t...

Linq and DB relationships

quick question here guys. I'm working with an older database, which had no relationships adn am now trying to make it as consistent as possible. the code that I'm porting had some quirks which led to some situations where I cannot enforce the relationship (PK <-> FK). I was wondering if this enforced relationship is a requirement for L...

Can SSMS display empty space as a character?

Right now I'm working on a dataset where I would like to return records where a certain field is NOT NULL. The dataset is result of a table join. My resulting set is still returning records where the field I told not to return NULL look empty. I'd like to see what the true value in these records are since they don't seem to be true NULL...

How do I use T-SQL's Exists keyword?

I have a query I want to run as a subquery that will return a set of FK's. With them I want to return only rows that has a matching key. Subquery: SELECT ID FROM tblTenantTransCode WHERE tblTenantTransCode.CheckbookCode = (SELECT ID FROM tblCheckbookCode WHERE Description = 'Rent Income') That will return all the transac...