sql-server

How to make a select query for sql and access databases?

Using SQL server 2000 and Access 2003 Access Database Name - History.mdb Access Table Name - Events SQL Database Name - Star.mdf SQL Table Name - Person I want to take the field from person table, and include in Events table by using inner join Tried Query Select * from Events inner join person where events.id = person.id So How...

Strategies to issue unique records via db?

Hi, We have more than 1 instances of a certain exe running from different locations. An exe is supposed to fetch a set of records and do some work based on them. The set of records fetched from exe A should not be fetched by exe B and vice versa. Exes A & B are the same exes; they are running from different locations. The number of inst...

SQL Insert with data from multiple tables.

I have four tables: Messages, MessageCategory, MessageStatus and MessageLevel. MessageCategory, MessageStatus and MessageLevel all just have three fields: Identity (primary key), Code and Description. Messages refers to these three fields and has a few other data fields, including Identity (primary key) MessageText and Order. The Identi...

PDF Binary Display on Page

I have a Binary Store in a SQL Server Table, In there I have PDF Files (in binary), what I want to do is display the PDF on a webpage in a "DIV". I dont want the user to have to press open so it opens in acrobat reader. I want a small thumbnail which they click and a model windpw opens with the PDF documet displayed as a picture. Does an...

Use SQL to count cases in a certain state at a certain time

Hi I need to develop a query that will count the total number of 'open' cases per month. I have a 'cases' table with an id and a name, and a 'state_changes' table with a datetime column, a caseid column and a state. How can I calculate the number of cases in each month that have a record with state 'open' in the past, but without a cor...

SQL Server Agent Job Timeout

I have just had a scheduled SQL Server job run for longer than normal, and I could really have done with having set a timeout to stop it after a certain length of time. I might be being a bit blind on this, but I can't seem to find a way of setting a timeout for a job. Does anyone know the way to do it? Thanks ...

Delete items older than a day - SQL Server

In a table in my datatase I have a datatime column which stores the time at which the record is added. How can I delete all records which are older than a day when I run a stored procedure (considering the current time) ? ...

Shortening GROUP BY Clause

Is it possible to shorten a group by clause so that you do not have to repeat the fields mentioned in the select clause ad nauseam? For example: SELECT field1, field2, field3, field4 FROM table GROUP BY field1, field2, field3, field4 to: SELECT field1, field2, field3, field4 FROM table GROUP BY SELECT.* ...

Will the Sql Server Import And Export Wizard have shapefile support anytime soon?

Do you know? PS: Some of you will tell me to check the Sql Server Management Studio features roadmap. But where is it? ...

How to make "No Duplicates" column in Sql Server 2008 ?

I have simple table in my SQL Server Database. This table contain two columns: ID int, Name nvarchar(50). The ID column is the primary key for my table. I want the "Name" column to be "(No Duplicates)", like in Microsoft Access, but this column isn't the primary column. How could I do this? ...

SQL Query : How to loop with inserting similar data

I have a SQL database (sdf file) I would like to create dummy records to fill in the database for a fixed size of say 22 MBytes. I have a simple insert command: INSERT INTO Log (Time, Source, MyID, SubID, Description) VALUES ('2009-09-17 01:20:35', '1', '1', '60', 'Test Record') What I need to do is be able to create a...

SQL Server: impact of column collation on T-SQL instructions

I discovered(*) today that, depending on the server, my TSQL commands were case-sensitive, meaning that, when one table's column is named tableId, the following instruction might not succeed: SELECT TableId FROM myTable Depending on the column's collation. SQL_Latin1_blablabla seems not to be case-sensitive, when Latin1_blablabla is. ...

Subtraction between two sql queries

I have 2 queries in MS SQL that return a number of results using the COUNT function. I can run the the first query and get the first result and then run the other one to get the other result, subtract them and find the results; however is there a way to combine all 3 functions and get 1 overall result As in: run sql1 run sql2 run SQL3...

T-SQL: Looping through an array of known values

Here's my scenario: Let's say I have a stored procedure in which I need to call another stored procedure on a set of specific ids; is there a way to do this? i.e. instead of needing to do this: exec p_MyInnerProcedure 4 exec p_MyInnerProcedure 7 exec p_MyInnerProcedure 12 exec p_MyInnerProcedure 22 exec p_MyInnerProcedure 19 Doing s...

How do I run SQL queries on different databases dynamically?

I have a sql server stored procedure that I use to backup data from our database before doing an upgrade, and I'd really like it to be able to run the stored procedure on multiple databases by passing in the database name as a parameter. Is there an easy way to do this? The best I can figure is to dynamically build the sql in the stored ...

SQL Server - Execute Stored Procedure with Output Parameter?

Hello, I have a stored procedure that I am trying to test. I am trying to test it through SQL Management Studio. In order to run this test I enter exec my_stored_procedure 'param1Value', 'param2Value' The final parameter is an output parameter. However, I do not know how to test a stored procedure with output parameters. How do I run ...

Disposing the Sql Connection

Just wondering, Would the SqlConnection be diposed/closed when this method is done? Or do i have to explicitly call the close method at the end? using (SqlCommand cmd = new SqlCommand(sql, GetConnection())) { SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { } } SqlConnection GetC...

Converting varchar to decimal in sql server 2008

I have this data as varchar '00072330'. How do I convert it to a decimal that looks like '723.30' in SQL Server 2008? ...

A covered index formed by a composite index or index with included columns

Are there any differences between these two covered indexes? A composite index with both FriendID and UserID A index with FriendID and UserID as an included column Separate MS SQL Server related point. If the answer to the above question is 'No difference', is it me or does the Database Engine Tuning Advisor (DTA) always go crazy on...

Best approach to views on archive data with change logs

(Sorry about the vagueness of the title; I can't think how to really say what I'm looking for without writing a book.) So in our app, we allow users to change key pieces of data. I'm keeping records of who changed what when in a log schema, but now the problem presents itself: how do I best represent that data in a view for reporting? ...