sql-server-2008

Using a User Defined Function in a View

I wrote the code for a View which needs to call a user defined function which returns a table to join with it. The problem here is passing the parameter that this functions needs straight out of my view. Below is the code of my view: select GG.Gid, GG.StockType StockType, COALESCE(STC.Contract, 0) ContractId, COALESCE(C...

Create nonclustered primary keys using NHibernate and SchemaExport

We're using SchemaExport via ActiveRecord. By default it generates a table like this: create table List ( Id UNIQUEIDENTIFIER not null, Name NVARCHAR(255) null, OwnerId UNIQUEIDENTIFIER null, primary key ( Id )) SQL Server then defaults to adding a clustered index for the primary key. But I want this to be nonc...

Retrieve last row inserted with Uniqueidentifier that it is not IDENTITY

Hi, I am puzzled with a query. I need find out the LAST row added in a table with a column with datatype Uniqueidentifier column is: aspnet_Applications.ApplicationId Notes: This column Uniqueidentifier it is NOT and IDENTITY Column. I need also take the last row inserted and update it on a different table aspnet_Users.ApplicationId I...

Can i set up sql server as master and my sql as slave in replication

Can i set up sql server as master and my sql as slave in replication? I can find only two subscriber ie.Oracle Subscribers and IBM DB2 Subscribers. how to add my sql>??? – Edit Sorry for not asking question properly,See we will be getting sql server backup from client every night,and we have to load it to my sql every night.so we my s...

What is different in SSIS SQL 2008 Standard vs Enterprise?

I spent half an hour trying to figure out what I cant do in SQL 2008 Standard in terms of importing data using SSIS pacakges vs Enterprise edition and simply couldnt find the answer.. I am sure someone already knows that.. Please tell !! :) ...

Indexed Views Don't appear to be equivalent to Oracle Materialized

Hi All, It has been quite a while since I used SQL Server and had been primarily working on Oracle DBs. I had grown accustomed to building materialized views off of my OLTP tables to speed up performance. I was excited to find information around what appeared to be the SQL Server equivalent of a Mat view...however, when I started read...

SQL Server Management Studio

Is it possible to install Management Studio by itself, and if so, is there a separate download/install exe for it? ...

Error when issuing BACKUP CERTIFICATE

I am creating a certificate in one of my databases, which works without a problem. However, when I try to back up that certificate so that I can port it over to another database I receive the following error message: An error occurred during decryption. Here's my backup statement: BACKUP CERTIFICATE test_certs TO FILE = 'C:\test_cert...

sql server invalid precision on exists check query

Using sql server 2008 I am getting and invalid precision value error in the following perl script: use DBI; $idx = '12345'; $query = 'if exists (select * from tbl where idx = ?) select top 10 * from tbl'; my $h = $dbh->prepare($query) or die "Couldn't prepare query: " . $dbh->errstr; $h->execute($idx) or die "Couldn't execute statement:...

writing t-sql version of .net codes by using sqlclr

hi, i have a lot of methods wrote with.net codes (c#) to using with linq queries. but i have problem to translating methods to t-sql. and i want to convert that to t-sql functions and using that with t-sql queries directly. how? ...

SQL Server 2008 - how to get records that have a specific range of IDs

Hi guys In SQL Server 2008 I would like to create a stored procedure to select specific products, passing their IDs as argument. But I intend to bring as result a range of products. This range must have the informed productIds argument value (for example: 1 and 8 and 29 - that means, the range MUST have productId 1 and productId 8 and...

How can I view the original SQL that created a stored procedure in SQL Server 2008?

The title pretty much says it all. How can I view the original SQL that created a stored procedure in SQL Server 2008? Is this possible? I've been searching online for some leads, but I'm either missing correct vernacular or I'm just looking for something that can be found by some other means. My basic problem is that I've got a SQL ...

Problem trying to fix SQL query to return a single result

I'm trying to use this query to delete the rows that are already on a linked server's Database: GO USE TAMSTest GO DELETE from [dbo].[Hour] WHERE [dbo].[Hour].[InHour] = (SELECT [InHour] FROM [TDG-MBL-005].[TAMSTEST].[dbo].[Hour]) GO When there is only 1 row in the linked server's table, SELECT [InH...

Interesting LEFT JOIN query question.

Well interesting to me at least... Say I have two tables: myLookUpTable: lookupId | Name -------- ----- 1 Red 2 Green 3 Blue and InfoTable: infoId lookupId Amount ParentId ------ -------- ------ -------- 1 1 2 332 2 3 14 332 How would I write a query t...

What type of database replication should I use?

I have 2 databases, one on local server and one on a remote server. I created a transactional replication publication on the local DB, which feeds the remote DB every minute with whatever updates it gets. So far, this is working perfectly. However, the local DB needs to get cleaned (all its information deleted) daily. THIS is the part ...

Build XML Off of Common Table Expression

Hi All, I am using a CTE to recurse data I have stored in a recursive table. The trouble is I am trying to figure out how I can use "FOR XML" to build the desired xml output. I have a Table of Contents table I am recursing and I want to be able to use that data to generate the XML. Here is an example of what the data is simliar to: ...

Finding duplicate rows but skip the last result?

Hello, I am trying to find duplicate rows in my DB, like this: SELECT email, COUNT(emailid) AS NumOccurrences FROM users GROUP BY emailid HAVING ( COUNT(emailid) > 1 ) This is ok, it returns me the emailid and the found matches. Now what I wanna do is to compare the ID column to another table I have and set a column there with the cou...

fastest way to search text value for words in SQL Server 2008

I have a requirement to identify keywords stored in a table column in text passed to a stord procedure, at present I'm pasing the text in as rows in a table value, however as populating the table value is hideously slow, I'm going to scrap this approach. I looked at the full text search option, however based on my very limited understand...

SQL: How to fill empty cells with previous row value?

I need to produce the column "required" in the following table using SQL without using loops and correlated sub queries. Is this possible in SQL 2008? Date Customer Value Required Rule 20100101 1 12 12 20100101 2 0 If no value assign 0 20100101 3 32 32 20100101 ...

Selecting columns in SQL

I have two tables and the following query: table1 --------- table1Id(pk) fromdate, todate, name, link table2 -------- table2Id(pk) url table1Id(fk) SELECT @ITEM = table1Id FROM table1 WHERE table1.FromDate <= @ToDate AND @FromDate <= table1.ToDate select * from table2 where table1Id =@ITEM Is it possible to select...