sql-server-2005

Sql Server: storing text and keeping newlines?

Hi, I suppose this question is kinda easy to answer, but I can't seem to figure it out. I'm trying to store text (email bodies) into a nvarchar(max) column, but when I go read it, the newlines are all gone. At first I thought this might be some encoding/collation problem, but it doesn't seem to be the case. I've searched around and ha...

Log of Queries executed on SQL Server

i ran a t-sql query on SQL Server 2005 DB it was suppose to run for 4 days , but when i checked after 4 days i found the machine was abruptly closed. So i want to trace what happened with the query or in other words whats was the status of the query when machine went down Is there a mechanism to check this ...

Frequency of inserts

Hello, I have a table, which holds (besides all other data) information, when this data was inserted. Now i would like to know frequency of inserts (number of inserts per hour (or per 15 minutes)). Below is code, what I want to achieve. Note that I also want to show time interval where no inserts occured (in my example from 10:00 to 11:...

How to display ndf files using SMO??

Hi I am using SMO to populate the list of database files log files. i am using filegroups but it displays only mdf and ldf files. I have ndf files also it is not dispalying ndf files?? what i have to do any suggestions plz??? string dbname = string.Empty, DatabaseInfo = string.Empty; Server srv = new Server(insta...

SQL query when using distinct

I want to know can I use distinct in different columns when writing a SQL query. If so then what is the statement if I have employee table that has id,name, salary, addr as columns ...

SQL Server: should I use an "Agent Job" or a "Maintenance Plan" to delete old data?

I'm looking for a way to periodically (e.g. weekly) run some SQL statements in a database to delete old data. As far as I can see, there are (at least) two ways to do this: using a "Maintenance Plan" and a "Execute T-SQL Statement Task" using an "SQL Server Agent Job" and specify the statements in a "Step" of that job My question is:...

Does the number of columns in a view impact performance?

I have a view that pulls about 200 columns from a table, no joins. The procs that use the view only use about 10 columns from it. Does having the extra 190 columns have a significant impact on performance using the view? EDIT: Just to clarify based on original questioner's comment, the query in his proc only uses 10 columns out of 200. ...

How do I convert this T-SQL query to use an explicit join syntax?

I have the following Select statement, but want to change it to use iner joins as I believe they are more efficient, but not too sure where to start. DECLARE @myNameID int DECLARE @myAddressID int DECLARE @myFirstName nvarchar(256) SET @myNameID = 1 SET @myAddressID =1 SET @myFirstName='Nathan' SELECT @myNameID = myNameID FROM ...

creating a table if it doesn't exist

Given the following: if object_id('MyTable') is null create table MyTable( myColumn int ) Is it not possible that two separate callers could both evaluate object_id('MyTable') as null and so both attempt to create the table. Obviously one of the two callers in that scenario would fail, but ideally no caller should fail, rather one sh...

Visual Studion 2008 App_Data defaults

Is it possible to use the App_Data folder in conjunction with SQL Server 2005? When I try it specifies Express even though I have changed the Tools>Options>Database>Data Connections to the correct server. I have downloaded SQLEXPR32_x86_ENU.exe Version 10.0.1600.22 file locally and have gone through 7 installs and deinstalls with a var...

Ad Hoc query assigns results to local variables

Hi is it possible for me to do this somehow? When i run the statement i get an exception, @Price_Plan is not delared, so obviously the adhoc query does not have scope to access @Price_Plan. Is there a workaround, or a better way to query a table whose name changes per execution of this query. DECLARE @Price_Plan varchar(3), @MNP_Network...

Sybase::TdsServer / MS-SQL emulation

Hello to All MSSSQL/Perl guru's, I want to emulate MSSQL/TDS-Server , so my 'Microsoft SQL Server Management Studio' (windows client) could SQL-SELECT(only READ) some distributed data that sits on Linux machines using regular-SQL query or linked-server ( and that's why i cannot use OLE DB Providers and their friends , i also cann...

How to call a sql script from another in SQL Server 2005

Hello to all, I am in need of testing several different processes for the application we're builduing. Each process requires a particular table in our database to have data and all of these tables have foreign key constraints from other tables as well. I've written sql scripts that populate the table I'm interested in as well as its de...

SQL Server query - Selecting COUNT(*) with DISTINCT

In SQL Server 2005 I have a table cm_production that lists all the code that's been put into production. The table has a ticket_number, program_type, and program_name and push_number along with some other columns. GOAL: Count all the DISTINCT program names by program type and push number What I have so far is: SELECT DISTINCT COUNT(*...

SQL SERVER Procedure Inconsistent Performance

I am working on a SQL Job which involves 5 procs, a few while loops and a lot of Inserts and Updates. This job processes around 75000 records. Now, the job works fine for 10000/20000 records with speed of around 500/min. After around 20000 records, execution just dies. It loads around 3000 records every 30 mins and stays at same speed...

SQL query in SQL SERVER 2005 - Comparing Dates

I'm having a hard time doing this query. I want to compare dates in my query, dates from my DB are in this format: (MM/DD/YYYY HH:MM:SS AM) I want to compare this date with tomorrow's day, today plus one. My questions are: How do I declare tomorrow's date in sql server? How would you compare these two dates? Thank you!! =D EDIT : DATE...

SQL Server - Storing linebreaks in XML data type

Is it possible to store non-alphanumeric characters (more specifically line break characters) in a XML data type? The code below illustrates my problem: declare @a xml declare @b nvarchar(max) set @b = '<Entry Attrib="1'+CHAR(13)+'2" />' print @b set @a=convert(xml,@b,1) set @b=convert(nvarchar, @a,1) print @b The output is: <E...

Bypassing word break in SQL 2005 Full Text

I have SQL Server 2005 with a Full Text index on a product table. I am running into issues with the word breaker parsing on the - (dash) character. If I have the following values in my [Keyword Search] field I see the following results; ABC-Z-XY more text... ABC-A-XY more text... ABC-ABC-XY more text... ABC-ABC-CE more text... -- brin...

MS Access error "ODBC--call failed. Invalid character value for cast specification (#0)"

Does anyone have an idea what this error means or how to solve it? I am using Access 2003 and SQL2005. It comes up when trying to add a record on a particular subform. [Microsoft][SQL Native Client] Invalid character value for cast specification (#0) This MS bug report describes the same message, but it is a bug in SQL Server 6.5 that...

Silverlight SQL 2005

I want to allow a user to provide their SQL login credentials, and display local SQL tables, stored procs, etc. in a listing. Is this possible? Note: I do not want to install some local, small SQL variant. I'm talking about the full version of SQL 2005+ that's already sitting on a developer's workstation. ...