sql-server

Inserting data into a Database

SO I'm making a "basic" login file where a person logs in and the data that person entered on that form gets transfered to another form aka my database/table. I think the problems is here but I'll post the rest of the code. CREATE FUNCTION dbo.Function4 ( parameter1 int = 5, parameter2 datatype ) RETURNS Table1 TABLE (UserName, P...

TSQL: Global Script Variable?

Hello all, I am making use of variables in my TSQL queries. As my script has grown, I have separated each part by GO, now the problem is I need access to variables at the top of my script. How can I still access these variables? Hopefully, this is something simple and straightforward. Thanks all ...

SQL Server tuning tools for finding overload

I use SQL Server as a DBMS for my very big corporate DB (with different financial data). And some times my system go down. I don't understand why. What programs/tools I can use for finding process/program/thread, that overload my SQL Server? Thanks for all answers! ...

Data warehousing in sql server 2008

Hi All: I am new to data warehousing and I am a little confused plz provide some simple steps to create a cube and fill it and make querey on it to know : I have a database with the original data and I have designed the star schema and made appropriate tables I have created an analysis service project in VS 2008 and then I have made the ...

What is new for developers in SQL Server 2008 R2

Today was released SQL Server 2008 R2. Was trying to find what is new (from the developer perspective), but the MS sites has all the PR blah, blah, blah. There is something new to be aware? ...

VB6 ADO Command to SQL Server

I'm getting an inexplicable error with an ADO command in VB6 run against a SQL Server 2005 database. Here's some code to demonstrate the problem: Sub ADOCommand() Dim Conn As ADODB.Connection Dim Rs As ADODB.Recordset Dim Cmd As ADODB.Command Dim ErrorAlertID As Long Dim ErrorTime As Date Set Conn = New ADODB.Connec...

Same query has nested loops when used with INSERT, but Hash Match without.

I have two tables, one has about 1500 records and the other has about 300000 child records. About a 1:200 ratio. I stage the parent table to a staging table, SomeParentTable_Staging, and then I stage all of it's child records, but I only want the ones that are related to the records I staged in the parent table. So I use the below que...

SQL Server + Select only two records for each masterID in a table.

I got a child table that contains 1 to n records linked to the master table via a MasterID column. How can I select from the child table only the first 5 records for each MasterID? ...

Query Results Not Expected

I've been a CF developer for 15 years and I've never run into anything this strange or frustrating. I've pulled my hair out for hours, googled, abstracted, simplified, prayed and done it all in reverse. Can you help me? A cffunction takes one string argument and from that string I build an array of "phrases" to run a query with, attem...

Using PIVOT in SQL Server

How can i convert below using PIVOT as Thanks ...

sort items based on their appears count

Hello Experts, I have data like this d b c a d c b a b c a c a d c if you analyse, you will find the appearance of each element as follows a: 4 b: 3 c: 5 d: 2 According to appearance my sorted elements would be c,a,b,d and final output should be c b d a d c b a b c a c a d c Any clue, how we can achieve th...

Replace table of one database with other

I have 2 databases with same tables. DBProduction and DBLocal both have testTable. How can i replace testTable of DBProduction with of DBLocal? There are some new rows inserted and some updated rows in testTable of DBLocal. Using SQL Server 2008 ...

Problem restoring a SQL Server backup

I have a SQL Server 2008, which is part of a domain. Now I make a backup of a database of this server and restore it on a SQL Server, which is not part of a domain. I have an C# application, which uses this database. On the NON-Domain machine I get now exceptions like this: "Cannot execute as the database prinzipal because the principia...

T-SQL Specific Syntax problem (Simple no doubt)

Hi guys, I have an issue with a query I'm trying to run on some data, I guess the place to start is to describe the data. Ok so I have a list of email addresses, each email address has a unique ID and an account ID Also in my tables I have a set number which auto incrememnts, this will allow me to target duplicate email addresses Wha...

Cannot open database "dbname" requested by the login. The login failed.

Hi, I'm trying to make a connection to sql server database(hosted on localhost) but keep getting the error mentioned in the title. Application("ConnectionString") = "Provider=SQLOLEDB;Data Source=localhost\SQLExpress;Database=mydb;Trusted_Connection=yes;UID=dbadmin; PWD=dbadmin" Application("ConnectionTimeout") = 15 Application("C...

Bulk Insert multiple records and get identity for all using ADO.NET

I want to batch insert multiple records in sql server database using ADO.NET command/sqldataadapter and get identity value generated for all the rows in a single database trip. What are my options? ...

Shrink database after removing extra data

We have a need to fit database in 4G in order to use ms sql express edition. I started from 7G database, and found a lot of not needed records, and deleted them. After Shrink database size is 4.6G, and 748MB is free (according to database properties). However, when i execute exec sp_spaceused i am having interesting results: Database...

Is there an automatic way to generate a rollback script when inserting data with LINQ2SQL?

Let's assume we have a bunch of LINQ2SQL InsertOnSubmit statements against a given DataContext. If the SubmitChanges call is successful, is there any way to automatically generate a list of SQL commands (or even LINQ2SQL statements) that could undo everything that was submitted at a later time? It's like executing a rollback even though ...

Django aggregate query generating SQL error

I'm using Django 1.1.1 on a SQL Server 2005 db using the latest sqlserver_ado library. models.py includes: class Project(models.Model): name = models.CharField(max_length=50) class Thing(models.Model): project = models.ForeignKey(Project) reference = models.CharField(max_length=50) class ThingMonth(models.Model): thin...

Do I need to change collation for database?

Hi, We have a number of customers in which we supply a database that was built using the collation SQL_Latin1_General_CP1_C1_AS. We now have to support Unicode to cater for other languages and thanks to the help of other at stackoverflow, I have now a script to change fields from varchar to nvarchar. However, to cater for all languag...