June 7, 2005 at 7:51 am
I have a table containing a number of columns, one column contains the record numbers for the records being inserted. The record numbers have the format: 2005/a/b/001, 2005/a/b/002 ..... and so on.
There is a possibility that some records may be added in duplicate but throwing an error. What I want to do is search the numbers column before the new record is inserted to see if that record already exists and if it does then I want ot generate new number.
I know how to generate new number but I need help to search the column.
Anyone know how to search the column to see if the record already exists?
Thanks.
June 7, 2005 at 7:55 am
Can you post the tables definition with some sample data, along with the expected output. Also the code to generate the newid would be nice. It'll be easier to help you then.
June 7, 2005 at 8:00 am
2005/a/b/001
Life would be easier when you would break this into separate columns. Is there a specific reason why you want to maintain such a sequence at all within your data?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
June 7, 2005 at 8:02 am
"2005/a/b/001" Doh!!, read this one too fast.
I would tend to agree with Frank on this one and ask the same thing??
June 7, 2005 at 8:32 am
I would assume '2005/a/b/001' is record number and is in one column.
Next recorde would be some thing like '2005/a/b/002' the '/' in the data is confusing.
IF EXISTS (SELECT * FROM Table WHERE Column = '2005/a/b/001' )
-- Logic to generate a new Code
ELSE
-- Do an update (UPDATE Table set Field = newvale Where Column = '2005/a/b/001' )
-- or Return
Regards,
gova
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply