sql-server-2005

Read from an existing text file(.txt) in sql server 2005

My gps device writes its data to a text file in my server. Now i want sql server to read it and store values in a table. How to get started with this kind of a scenario? Any suggestion. EDIT: Consider it is an existing file with 10 rows and i have already imported it. Now the file gets updated with new 10 rows. How to import the new row...

How can i add the same value in to the different tables that are in different databases

I am having 2 databases namely ach and cart and i am having tables namelt Register and Invoice i would like to add a field in to those 2 tables . Like if i enter a value like some ccyyxxyxyxa this should be saved in the 2 tables... ...

Select Top (some number) with UNION ALL and ORDER BY

I am trying to pull back the top five instances of certain records loaded into a table. It is important to note that I am trying to get my results out of the same table and I think there is a problem that I can't quite figure out related to the fact that this is one table. Here is the example of my query: Select * From ( Select Top 5 ...

how to select comments for each row

I have events table which include so many cols besides Id PK and table Comments which includes text, eventId and Id PK . how can I select the event information and it's comments in one single sql statement, how to use it and how it should look like !? Note that EventId(Comments) = Id(events) ...

how to write query for optional parameters

hello friends i am following 3 layer architecture for my project i mean presentation layer, business logic layer and finally database layer my question is that i am making a search feature for my project where i need to send parameter through a method for search query which is to make on business logic layer i am to send parameter from ...

SQL Server 2005 Express: In Database Properties Transaction log filegroup currently says 'Not Applicable'

Hi The database files (mdf ldf) were taken from a crashed machine and loaded using the attach method. Since everything has been working fine, except when i try to truncate the transaction log the file size does not change and i now notice that it says Not Applicable against the filegroup entry for the transaction log in database propert...

SQL Server 2005 Converting Data Type Error

I am trying to import varchar data into a varchar data type field but I am getting a conversion error of varchar cannot be converted to date type bit? How is that when both fields are already varchar type? Conversion failed when converting the varchar value 'JOHN KUCHTA' to data type bit. ...

Select a data from MS SQL Server 2005

I have a table named t_Student in Microsoft SQL Server 2005 database. In that table there are three columns named student_regiNo, student_Name, student_Email. I'm using following code segment to retrieve "student_Name". But instead of showing "student_Name" it shows "System.Data.SqlClient.SqlDataReader". Whats the problem? private ...

INSERT from SAS 9.2 to SQL Server 2005 fails when table has a trigger

I connect to an SQL Server 2005 DB from SAS 9.2 via SAS/Access ODBC Driver. In the DB, I have a table my_table, which has an INSERT-trigger that copies all the inserted rows into another table in the database. In the SQL Server environment, the trigger works normally. However, SAS Proc SQL doesn't seem to get on well with a table with t...

sql view running slow

Hello Experts, I have a sql(2005) view which is running very very slow its takes 5 mins to run. But when i rip out the query from view and run it naked it hardly takes 5-6 seconds. Can some one please advise me on how i can check what's going wrong with the view Thanks Amit ...

How to do Encryption and Decryption in Sql Server 2005

I want to encrypt and decrypt data with sql server using RSA or SHA algorithm rahter than doing it at UI. Is it possible to do this. Some Code Snippet will be a great help ...

Nightly database restores - SSIS package - SQL Server 2005

We have an SSIS package that runs nightly which takes the backup of a couple of production databases, restores to a staged database, sensitive information is removed and then the backup of this staged database gets restored on another server so that the hyperion guys can run their jobs. The whole process used to take around 4 and half ho...

sql query takes more time when run in a view

HI all, I have a huge sql query. When i put that query in a stored Proc it takes 5 seconds to execute which i run it just as a query it takes 4-5 seconds but when i run it in a view it takes 5 mins. Please advise why its running that slow in a view sql query is below: CREATE VIEW dbo.Client_Billing_RS AS SELECT DISTINCT...

Converting a stored procedure into user defined function

Hi, i need help in converting a stored procedure to a function, CREATE PROCEDURE [dbo].[FunGetEmpExp] ( @fromdate DATETIME,@todate DATETIME) AS BEGIN DECLARE @TotalYears VARCHAR(2) DECLARE @TotalMonths VARCHAR(2) DECLARE @TotalDays VARCHAR(2), @Duration varchar(10) SET @TotalYears = null SET @TotalMonths = NUL...

Why does "SELECT DISTINCT a, b FROM..." return fewer records than "SELECT DISTINCT A + '|' + B FROM..." ?

I have a query that's selecting a bunch of fields related to names and addresses of customers but it boils down to: SELECT DISTINCT a, b, c, ... FROM big_dumb_flat_table it returns a bunch of records (10986590). When I replace the commas in the select-list to format it as a pipe-separated concatenated string: SELECT DISTINCT a + '|'...

SQL: Expanding a row with start/end into individual rows

Hello I have a records like this: start, end , total 830 , 1300, 5 1400, 1430, 2 that I'd like to expand to: instance , total 830 , 5 831 , 5 832 , 5 ... 1299 , 5 1300 , 5 1400 , 2 1401 , 2 ... 1429 , 2 1430 , 2 How can I do this using SQL in MSSQL 2005? EDIT...

Please tell me why this code is throwing an error.

I can not for the life of me figure out what is wrong with this code: IF NOT EXISTS(SELECT * FROM sys.columns WHERE name = 'Report_Date' AND object_id = OBJECT_ID('TempTable3')) ALTER TABLE TempTable3 ADD Report_Date datetime --Set "ReportDate" field to the date the data was extracted less one. UPDATE TempTa...

SQL group by clause understanding (simple question / SQL server 2005)

HI all, I'm having some difficulty understanding the rationale behind group by aggregation in sql server 2005. I have the following query which works fine and returns one row for each contact.id and the 1st occurence of event SELECT contact.id ,MIN(eve.date_created) FROM _contact contact WITH(nolock) INNER JOIN table2 tb2 WITH (nolock)...

Checking if something has changed in a trigger

I have a need to monitor a subset of fields on a table and perform a task when one of them changes. I am using a trigger on the table update which and then am looking at the changes as follows: -- join the deleted and inserted to get a full list of rows select * into #tmp from (select * from inserted union select * from deleted) un -- ...

SQL Server Mangament Studio 2008 unable to connect to SSIS packages on SQL Server 2005

I get an "Class not registered" error whenever I attempt to connect to the integration services on sql server 2005 from within SQL Managment Studio 2008. Is there a workaround? or do I have to downgrade to SQL managment studio 2005? ...