July 15, 1999

Reporting duplicates

Question: I am having trouble figuring out how to make a report dealing with duplicates. I need to selcet from a table only instances where the first 10 characters of two columns match. For example, I combine the first and last name columns with (||), then I need to take

Identity?

Question: I’m trying to get the Identity of records as I insert them into my database. I have tried: OrderID = DataConn.Execute(“SELECT @@IDENTITY FROM Orders”). But this returns a syntax errorat ‘@@IDENTITY’. I am using JScript with NT4 and MS Access. Answer: What you really want is to select the

Generate Numbers

Question: I have a field in one of my SQL Server Database tables which I want to increment every time a user enters a new record. I thought about a trigger, but in a multi-user environment the max function may return the wrong number. Is a stored procedure more efficient?

Finding the Latest Date in SQL

Question: I have a table with a datefield as part of the key. This was needed because it stores historical information. I need to know how to write an SQL query that will supress all records except those with the “latest” date. The other part of the key is a

Auto assigning primary key values

Question: Is there a way to have SQL Server assign values to key fields automatically, so that every time a new record is added it just increases the prior record’s key by one? Answer: Yes, you can either use the Identity function (you need to create a column in your

About tables

Question: Please describe the basic components of a table in the relational model. Answer: A table has an intension and an extension. You can think of the intension of a table as the names of its columns, so the intension describes the thing the table is about.The extension of a

Connection

Question: I have a small SQL Server 6.5 database running on NT Workstation. From my workstation I can ping that machine and I can map a drive to that machine. However, every time I try to connect through SQL Server I get a network error stating that the SQL database

How to use Union on two databases?

Question: I want to use Union to union two different tables, but they are in different databases. An error message told me that I can’t use Union in this way. How can I do that? Both tables use the same schema. Answer: You have to prefix the query with the

Searching for matching strings

Question: I have a simple query using an SQL statement for returning matching records from an IIS Web server using ASP. I need a new query which returns a match on a search string which occurs anywhere in the searched field. In other words a search for “fox” would match

No more posts to show