sql-server-2005

How do I copy records from one database to another?

I need to pull data from one SQL 2005 Express database to another and I need to do this periodically. It is not a straight copy from one table to another, but I would use different views from the source table. I also need to do this periodically. My first idea is to write a small application in C# and run it somehow in every hour or so...

Manipulate sql Server database in vb.net

Do you know of any beginner tutorial on how to manipulate(Add, Edit, Delete, Search, List) sql Server database in vb.net? ...

Sql 2000 database to Sql 2005 express db

Hello I have a database that is on a SQL 2000 server, and I would like to make it a Sql 2005 express edition database. What is needed to do in order to make that work? /M ...

SQL Server search filter and order by performance issues

We have a table value function that returns a list of people you may access, and we have a relation between a search and a person called search result. What we want to do is that wan't to select all people from the search and present them. The query looks like this SELECT qm.PersonID, p.FullName FROM QueryMembership qm INNER JOIN dbo...

SQL Bits vs Datetimes to determine the logical state of a record

Hey everyone, I have this question that keeps coming up over and over in terms of best practices. Lets say I have the following table: [Process] ---------------- ProcessID int ProcessName varchar(100) ... In addition to the fields above, lets say a [Process] can have various states. It can be currently successful, currently unsuccess...

SQL server query to get the list of columns in a table along with Data types, NOT NULL, and PRIMARY KEY constraints

Hey guys. I need to write a query on SQL server to get the list of columns in a particular table, its associated data types and their length and if they are not null. I have managed to do this much. But now i also need to get in the same table against a column - TRUE if it is a primary key. How do i do this ? This is how the output s...

Is there a way to rename a similarly named column from two tables when performing a join?

I have two tables that I am joining with the following query... select * from Partners p inner join OrganizationMembers om on p.ParID = om.OrganizationId where om.EmailAddress = '[email protected]' and om.deleted = 0 Which works great but some of the columns from Partners I want to be replaced with similarly named columns f...

How to call an extended procedure from a function

hi im having trouble trying to get the following function to work. CREATE FUNCTION test ( @nt_group VARCHAR(128) ) RETURNS @nt_usr TABLE ( [name] [nchar](128) NULL , [type] [char](8) NULL , [privilege] [char](9) NULL , [mapped login name] [nchar](128) NULL , [permission path] [nchar](128) NULL ) AS BEGIN ...

where clause from where clause

i need to do this : There is a table called table1 it has a employee id column,status column which has values 1 and 0 only and a department column with values 100,101,102. i want to list all employeeid with the status = 0 and (department=100 whose status=1) Please help me ...

Where clause in where - version 2 :-)

i need to do this : There is a table called table1 it has a employee id column,status column which has values 1 and 0 only and a department column with values 100,101,102. i want to list all employeeid with the status = 0 from the above list i want to filter the employees which having (department=100 and whose status=1) Extended que...

SQL Server 2005 Convert VARCHAR to INT but default on invalid type

I have a varchar(100) column in a table that contains a mix of integers (as strings) and non-integer strings. E.g. | dimension varchar(100) | | '5' | | '17' | | '3' | | 'Pyramids' | | 'Western Bypass' | | '15' | How can I write an expression to...

SSIS Package won't fail, even with bad input data

Hi everyone, I have an SSIS package that won't error out even with bad input. In my case this package reads from a flat file and puts records into a SQL Server table. Pretty straightforward, nothing fancy going on here. The flat file is defined as being ragged right, 80 characters per row, maybe 10 columns in total. Problem: sometim...

Slowness at Indexed View for SQL 2005

Hi, Say I have a very long table (~35 million rows) called TimeCard with only 5 columns (tableID, CompanyID, UserID, ProjectID, DailyHoursWorked, entryDate). This is a pretty straight forward table that records employees' worked hours per day per project per company. I now need to generate a report to find out the employees' total wo...

Debugging a tough LINQ-to-SQL Timeout

I'm getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Now, this is not just a case of a slow query: I run the equivalent SQL in SQL Management Studio and it com...

How to prevent out-of-range datetime value error?

I am passing an ad-hoc Insert statement from c# application to the sql server 2000/2005. Sometimes, if machine (where sql server is installed) datetime format is different than what I am passing in, it is throwing an error. e.g. : In Insert statement I am passing '2010-03-10 00:00:00-05:00' this but machine regional date setting is dif...

Trying to list data in ms sql using vb.net

Below is the code that I'm using in ms access to list the data according to what is selected in combobox and what is input in textbox. My problem is there no commandbuilder in ms sql like in ms access, because it fails when I try: dim mscombuilder as new sqlcommandbuilder Here is the code: ''#list school If ComboBox1.SelectedItem =...

SQL query to fetch products with most top 1 most recent price change.

I'm using SQL Server 2005. Let's say I have a table for products and another table for prices so that I can track price changes over time. I need a query that fetches distinct products (easy part) plus each product's most recent price and the date it changed. Products Table: CREATE TABLE [dbo].[Products]( [ID] [int] IDENTITY(1,1)...

Stored procedure to script database objects to file?

I'd like to write a stored procedure in SQL 2005 to script all my database objects to a file. The only problem is...I have no idea how to do it. Can anyone help? Thanks! ...

pivoting on a column without knowing the entire list of values

I have a table Title Name Type ------------------------------------------------ T1 A Primary T1 B Primary T2 B Primary T2 C Secondary T2 D Secondary I need the output t...

How do you add a NOT NULL FOREIGN KEY column to an existing (populated) table in MS SQL?

I need to add a NOT NULL column to an existing (populated) table that will be a foreign key to another table. This brings about two problems: When you add the column, its value cannot be null - using a default is not an option (unless it is removed later on) because the database logic is used in the server side validation when a user e...