sql-server

Adding a type of heading to a query

Hey all, im not sure if this is possible but i am looking to add a heading to a query's output. The best way to describe this is just by showing what i would like the output to look like: [heading here] <skip row> [Another Header here] MemebersID | FirstName | LastName | Email | OrderDate 05466 Bob Barker ...

SQL Server recursive query

Hello, I am new to SQL Server development. Most of my experience has been done with Oracle. suppose I have the following table that contains Appointments objects CREATE TABLE [dbo].[Appointments]( [AppointmentID] [int] IDENTITY(1,1) NOT NULL, ....... [AppointmentDate] [datetime] NOT NULL, [PersonID] [int] NOT NULL, ...

Help with sql query

Hello, I'm doing an sql query where I want to return a list that will contain the users / groups who will have access to an application. This is the scheme, we will see if a user have permissions, if not, we going to see the group. If both not, we see if there are any permissions on the application, if not, then will add the user to the ...

Recursive SQL query to speed up non-indexed query

This question is largely driven by curiosity, as I do have a working query (it just takes a little longer than I would like). I have a table with 4 million rows. The only index on this table is an auto-increment BigInt ID. The query is looking for distinct values in one of the columns, but only going back 1 day. Unfortunately, the Re...

where like over varchar(500)

I have a query which slows down immensely when i add an addition where part which essentially is just a like lookup on a varchar(500) field where... and (xxxxx.yyyy like '% blahblah %') I've been racking my head but pretty much the query slows down terribly when I add this in. I'm wondering if anyone has suggestions in terms of chan...

How to export MS SQL database to MYSQL?

I'm trying to convert from a MSSQL .bak database to MYSQL. This question and answers have been very useful, and I have successfully imported the database, but am now stuck on exporting to MYSQL. The MYSQL Migration Toolkit was suggested, but seems to have been replaced my the MYSQL Workbench. Is it possible to use the MYSQL Workbench to...

Make connection to database only once on page load

When I load my page I populate my repeater with the following code. Dim conn As Data.SqlClient.SqlConnection Dim Comm As Data.SqlClient.SqlCommand Dim reader As Data.SqlClient.SqlDataReader 'conn = New Data.SqlClient.SqlConnection("Server=localhost\sqlexpress; " & _ '"Database=MyDB; Integrated Se...

Taking median of calculation in SQL Server

MyTable in SQL Server contains _TimeStamp, Column1, Column2, and Column3, which have the following values: _TimeStamp Column1 Column2 Column3 '2010-10-11 15:55:25.40' 10 3 0.5 '2010-10-11 15:55:25.50' 20 9 0.7 '2010-10-11 15:55:25.60' 15 2 1.3 '2010-10-11 15:55:25.70' 17 8 2.7 '2010-10-11 15:55:25.80' 42 6 3.6 '2...

Delete multiple duplicate rows in table

I'm sure this has been asked before, but I was having a hard time finding it. I have multiple groups of duplicates in one table (3 records for one, 2 for another, etc) - multiple rows where more than 1 exists. Below is what I came up with to delete them, but I have to run the script for however many duplicates there are: set rowcount ...

Grouping multiple counts with each row representing one ID

Hi, I have a table that logs activity. It has an int activity column that indicates what type of activity it was and a corresponding admin_id that indicates which admin performed the action. Each row in the table represents one action, so for example, an administrator would cancel a user's account, and a row with that admin's id and acti...

Returning values in two rows that aren't equal

I'm trying to return the results of a query where two columns columns are not equal to each other. However, when I run the query the results don't seem to be consistent with the actual data. As you can see below, I want to return rows where the RatePlanIDs are different. RatePlans_Supplemental.PIDs could actually be null, but I n...

IIS to access SQL server on different machine

I have a Gui running on a server with the IIS and the SQL database both on the same machine. I have this connectionstring in the webconfig. Data Source=localhost\SQLEXPRESS;Initial Catalog=XYZDB;Integrated Security=True Now i want to access another database on a different server, i thought it would just take me to change "localhost" ...

SSIS Flat File Unpivot

Hello, I have a rather complex Flat File that I'm trying to parse using SSIS. The overall structure of the flat file is as follows: CustomerName, CustomerAddress, CustomerContactInfo, InvoiceDate1, InvoiceAmount1, InvoiceDate2, InvoiceAmount2, InvoiceDate3, InvoiceAmount3 I'm trying to load this into two tables in my database, a Cust...

How to fetch data from two different sql servers?

Hi, I have an inline query, in which I have one table1 in server1 and another table2 in server2. I need to join these two tables, and fetch data. I can do this like connect to one server, get data and connect to next server...fetch data. and join them. But is there any other better way. I have heard about Linked servers. Will that hel...

SQL Query - Ensure a row exists for each value in ()

Currently struggling with finding a way to validate 2 tables (efficiently lots of rows for Table A) I have two tables Table A ID A B C Table matched ID Number A 1 A 2 A 9 B 1 B 9 C 2 I am trying to write a SQL Server query that basically checks to make sure for every value in Table A there exists a row for a v...

IN NOT IN SQL Server 2005

How can I see what is not in the table... I know I know...can only see what is there but come on!!! So!! select * from ORDER where State IN ('MA','PA','GA','NC') So I will get MA and PA but I want to see GA and NC.... NOT IN will return NY,NJ,CT ect.... I just want to see what is in the ( ) ...

What is the difference between using a cross join and putting a comma between the two tables?

What is the difference between select * from A, B and select * from A cross join B ? They seem to return the same results. Is the second version preferred over the first? Is the first version completely syntactically wrong? ...

Compound foreign key with nullable column

In the following table, is there a way to ensure PreviousID always references an ID in a row with a matching ParentID, or, if ParentID is null, it is also null in the referenced row? CREATE TABLE MyTable ( ID int not null identity(1,1) primary key, ParentID int null foreign key references MyTable (ID), PreviousID int null foreign ...

IsDeleted is not working in SubSonic 3.0

Hello, I'm using SubSonic 3.0 with SqlServer and for some reason the IsDeleted field is not being autopopulated to false. It remains null. Is there a quick fix for this in the templates? My field schema is IsDeleted bit null ...

Is there a way to have a SQL statement return a string value from a map that has an integer as the key?

For example: In the database we have number representations of fields that correspond to strings in the app. We store the data as an integer for size and speed reasons. During testing we compare what's in the app with SQL statement results. The problem is that we see the numbers in the results but there are strings in the app. There is ...