sql-server-2008

t-sql create user and grant execute on permission for stored procedures

Hi I have a script which creates a database, stored procs, views, tables, udf. I want to include a script to create a user 'user_1' and give execute permission on the database. update I tried following to create grant exec command for all stored procs use DB; go declare @permission varchar(max) select @permission = COALESCE(@permi...

Can UNION ALL be faster than JOINs or do my JOINs just suck?

I have a Notes table with a uniqueidentifier column that I use as a FK for a variety of other tables in the database (don't worry, the uniqueidentifier columns on the other tables aren't clustered PKs). These other tables represent something of a hierarchy of business objects. As a simple representation, let's say I have two other tabl...

SQL 2008 HierarchyID support in NHibernate

Searched various NHibernate lists and haven't come up with a definitive answer. The SQL2008 dialect doesn't appear to have support for the HierarchyID data type - new date and time types only. Does anyone have a good implementation or an effective workaround? I'd really like to leverage HierarchyID in a new app of mine. Support for t...

How do I get a non-null SCOPE_IDENTITY when using INSTEAD OF triggers in SQL Server 2008?

Possible Duplicate: Instead of trigger in SQL Server - looses SCOPE_IDENTITY? On SQL Server 2008, I have an INSTEAD OF trigger on a view. The SCOPE_IDENTITY() after the trigger is results in null. This causes problems with the libraries we're using. How can I control SCOPE_IDENTITY from within my trigger? This is absolutely n...

SQL 2008 - resultset order issue

We are using SQL Server 2008. We have a table called response which has a primary key called response_id. It also has a column called bid_id. When we execute the query ‘select * from response where bid_id = x’ without an ‘order by’ we are getting results in mostly ascending order (default), but once in a while in descending order (ve...

Calculate TF-IDF using Sql

Hello, I have a table in my DB containning a free text field column. I would like to know the frequency each word appears over all the rows, or maybe even calc a TF-IDF for all words, where my documents are that field's values per row. Is it possible to calculate this using an Sql Query? if not or there's a simpler way could you pleas...

Why difference in performance between the TWO queries?

I am using SQL Server 2008, and I have two tables Table1 contains 3.5 million records +----+-------------+ | pk | dim1 | +----+-------------+ indexing applied on column **pk** Table2 contains 15 million records +----+-------------+ | fk | fact1 | +----+-------------+ indexing applied on column **fk** I ran 2 querie...

Difference between login and user in sql server

CREATE USER [anc] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[anc] GO what is the difference between the user and the login. i am not clear as to y do we create these kind of users?? ...

SQL Server query degrades over time from 0 to 60msec

Hi guys. I need some help in explaining this behavior in SQL Server 2008. I have a simple c++ program that is running a query in a loop. Here is the pseudocode of the program. myTempid = 0; while (1) { execQuery(select a.id from a,b,c,d where a.id = b.id and b.id = c.id and c.i...

SQL 2008: getting rows with a join to an XML field?

Hi there, Not sure if this question makes for some poor performance down the track, but seems to at least feel "a better way" right now.. What I am trying to do is this: I have a table called CONTACTS which amongst other things has a primary key field called memberID I also have an XML field which contains the ID's of your friends (fo...

Did not recognize the correct database after WCF project host in IIS 7

A WCF project consist of all the logic behind a desktop application (WPF) and it works well when I run it on VS 2008 with WCF selfhost. The desktop application consume services expose by the WCF and desktop application users have to login to the app using his username and password. WCF is connect with SQL Server 2008 database through LI...

SQL Server 2008 GEOMETRY.AsGml() In Views With Joins

Hello, I have a table that contains a GEOMETRY data type. SQL Server 2008 ships with a built in function to convert these GEOMETRY data types to GML - GEOMETRY.AsGml(). I believe this function is nothing more than a custom user defined function. This function works exactly as expected, until I try to use it in a view that is joined t...

tsql for loop on a list

How can I write this code in T-SQL? var categories = new []{ "cat1", "another category", "one more" }; for (var i = 0; i<categories.count; i++) { insert into Categories (id, name) values (i, categories[i]) } Is it possible? ...

Master database DB STARTUP problem

I have a SQL Server 2008 database and I have a problem with this database that I don't understand. The steps that caused the problems are: I ran a SQL query to update a table called authors from another table called authorAff The authors table is 123,385,300 records and the authorsAff table is 139,036,077 The query took about 7 days e...

Accessing a SQL Server 2008 Express Database Using TCP/IP

VS 2010 comes with SQL 2008 Express, and upgrades existing project's databases to SQL 2008 as well (please correct me if im wrong!) - however, I now have a problem - I need to simulate a hosting situation on my PC, where a desktop application connects using TCP/IP to the SQL 2008 database. Problems 1. The database as created in VS 2010 ...

update duplicate or similar records in the same table

I have a table that allows records to be inserted which are very similar but differ by a single column value or two. For example the following records are in the table: ID TITLE URL COUNTRY 1494 Hollywood Reporter http://www.hollywoodreporter.com USA...

How Can I Sum Vat in a column in sql server 2008?

Hi all suppose i have the following table CREATE TABLE #ResultTable (NettAmount money, GrossAmount money,TotalVat money) Given a gross amount eg=250 I know that vat is at 17.5% How Do i calculate the totalVat? Thanks for any suggestions ...

Reporting Services permissions on SQL Server R2 SSRS

I'm getting the error below when I try and access SSRS on SQL Server 2008 R2 I'm not sure how many others have started using SQL 2008 R2 SSRS, but I am having an issue with getting the error below when I try and access the reports server url "User does not have required permissions. Verify that sufficient permissions have been granted ...

SQL selecting from a particular duplicate row

Hi all I have a sql query SELECT FKid1, FKID2, a, b, c from [source] where FKID1 = 3 which returns the following data set so (hope formatting holds) FKID1 FKID2 A B C 3 40297 0 0 2 3 40297 0 100 1 3 40325 0 0 2 3 40325 0 0 3 3 40325 0 10 -1 ...

sql server table contains special foreign characters

I realized after populating the table that it contains special encoding for foreign characters. I changed it to nvarchar but how do update the records already in the table since I still see it in the table. for example Börsenblatt ...