I have two tables:
customermaster (id,name,email,mailinglists)
example: 1,john doe, jo*****@nowhere.com, NULL
emailmaster (email,listid)
example: jo*****@nowhere.com 1 jo*****@nowhere.com 8
I want to get rid of the emailmaster table and merge the listids, into
the mailinglists field inside customermaster so that I will have
something like 1,8,14,25,99 in the mailinglists field for the email
address jo*****@nowhere.com
How can I accomplish this for MS SQL database?
*** Sent via Developersdex http://www.developersdex.com *** 2 1455
Why do you want to do that? That is not a good database design by any
means, in my opinion. Actually, what I think you should do is keep your
emailmaster table, but drop the email column and replace it with a
customerid column that holds the ID column from the customermaster table.
Ray at work
"Joey Martin" <jo**@infosmiths.net> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl... I have two tables: customermaster (id,name,email,mailinglists) example: 1,john doe, jo*****@nowhere.com, NULL
emailmaster (email,listid) example: jo*****@nowhere.com 1 jo*****@nowhere.com 8
I want to get rid of the emailmaster table and merge the listids, into the mailinglists field inside customermaster so that I will have something like 1,8,14,25,99 in the mailinglists field for the email address jo*****@nowhere.com
How can I accomplish this for MS SQL database? *** Sent via Developersdex http://www.developersdex.com ***
Joey Martin wrote: I have two tables: customermaster (id,name,email,mailinglists) example: 1,john doe, jo*****@nowhere.com, NULL
emailmaster (email,listid) example: jo*****@nowhere.com 1 jo*****@nowhere.com 8
?
This does not seem to be an "emailmaster". It seems to be more of a "bridge"
table to resolve a many-to-many link between customermaster and perhaps a
table called listmaster...
I'm wondering why email was used instead of the id from the customermaster
....
What are the datatypes? is listid numeric or character? I want to get rid of the emailmaster table and merge the listids, into the mailinglists field inside customermaster so that I will have something like 1,8,14,25,99 in the mailinglists field for the email address jo*****@nowhere.com
This is a HORRIBLE idea. By storing multiple pieces of data in a single
column, you are reducing the ability of the databse to maintain the
integrity of the data, as well as making it much more difficult to write
some queries to retrieve data. Maintaining this data will be a nightmare as
well.
Have you truly thought this through? Run it by someone who knows something
about database design? You really should consult somebody ...
How can I accomplish this for MS SQL database?
What version? If 2000, you can create a UDF (I've taken a guess as to the
datatypes and sizes required):
CREATE FUNCTION dbo.ConcatRows (
@email varchar(80))
RETURNS varchar(500)
AS
BEGIN
DECLARE @val varchar(500)
SET @val=''
SELECT @val= @val +
CASE @val WHEN '' THEN '' ELSE ',' END
+ CAST(listid as varchar(10))
FROM emailmaster
WHERE email = @email
RETURN @val
END
Then, you can use the UDF in an update statment, like this:
UPDATE customermaster
SET mailinglists = dbo.ConcatRows(email)
If SQL 7, you are going to need to do some cursor work, either in T-SQL, or
using an ADO recordset from ASP.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Newbie |
last post by:
Hi,
I am trying to merge data from two tables (over two servers, using
dblink). Approx 40,000 records in each. Server1(source) and
Server2(dest)
On Server1, db-link "dblink1" points to...
|
by: Kevin King |
last post by:
I have a question about an assignment I have. I need to count the
number of comparisons in my merge sort. I know that the function is
roughly nlog(n), but I am definately coming up with too many...
|
by: Steve M |
last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a
Python script. The situation is that I have a template Word document,
and a record that I've generated in Python, and I want...
|
by: William Wisnieski |
last post by:
Hi Everyone,
Access 2000
I have some code behind a button that performs a word merge with a query
data source. The merge works fine. But what I'd like to do somehow is
after the merge is...
|
by: Squirrel |
last post by:
Hi everyone,
I've created a mail merge Word doc. (using Office XP) , the data source is
an Access query.
Functionality I'm attempting to set up is:
User sets a boolean field to true for...
| |
by: Andy Davis |
last post by:
I have set up a mail merge document in Word 2003 which gets its data from my
Access 2000 database. I want to set up a button on a form that:
1. runs the query to provide the dat for the merge...
|
by: Linda Cacina |
last post by:
Hello all you fine folks,
Here is some code I am using to merge data from a single record Access
2K3 table into a NEW word document based on a pre-defined Word merge
template doc. All I want to...
|
by: John Cosmas |
last post by:
I have a DATATABLE which I have populated in my application, and I need it
written out to a particular table I specify in my ACCESS database. My code
works to the point of the MERGE and UPDATE,...
|
by: Ron B |
last post by:
Help!!!
What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table.
I want to...
|
by: crealesmith |
last post by:
Firstly, I have no problem with mail merging to Word, VB code for that
works perfectly.
On one mail merge I need to merge 15 fields of data that are from 3
seperate records.
The 3 records are all...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |