Hi everyone
I guess this should be a simple question for the gurus
I have a Data in a column which is to be places in 2 columns instead of
one. How do i go about doing it in MS SQL server? Could someone please
help me. I could do it in access with an update query but things are a
little different in SQL server so I am a little lost.
Eg.
Name
John?Doe
to be split into
Name LastName
John Doe
Thanks in advance.
Prit 6 21875
"Prit" <pr****************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Hi everyone I guess this should be a simple question for the gurus I have a Data in a column which is to be places in 2 columns instead of one. How do i go about doing it in MS SQL server? Could someone please help me. I could do it in access with an update query but things are a little different in SQL server so I am a little lost.
Eg. Name John?Doe to be split into Name LastName John Doe
Thanks in advance. Prit
You can use string functions:
declare @name varchar(20)
set @name = 'john?doe'
select left(@name, charindex('?', @name)-1), right(@name,
len(@name)-charindex('?', @name))
So something like this?
insert into dbo.Destination (fname, lname)
select left(fullname, charindex('?', fullname)-1), right(fullname,
len(fullname)-charindex('?', fullname))
from dbo.Source
Simon
Simon
Thanks for the reply. It does work with the insert query. When I tried
to use it with an update query it did not quite like it. I wasn't sure
what was going wrong. Sorry I am still trying to find my way around the
SQL server. Does it have a update query equivalent of MS access?
thanks
prit
On 13 Jan 2005 12:52:27 -0800, Prit wrote: Simon Thanks for the reply. It does work with the insert query. When I tried to use it with an update query it did not quite like it. I wasn't sure what was going wrong. Sorry I am still trying to find my way around the SQL server. Does it have a update query equivalent of MS access? thanks prit
Hi Prit,
This UPDATE should work just as well:
UPDATE MyTable
SET fname = left(fullname, charindex('?', fullname)-1),
lname = right(fullname, len(fullname)-charindex('?', fullname))
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Hi Hugo
Thanks for the reply
It gives me the following error
Server: Msg 8114, Level 16, State 5, Procedure Part_Trigger, Line 26
Error converting data type varchar to numeric.
Surprisingly enough both my variables are varchar (50)
Any ideas why this is happening?
On 13 Jan 2005 14:50:44 -0800, Prit wrote: Hi Hugo Thanks for the reply It gives me the following error
Server: Msg 8114, Level 16, State 5, Procedure Part_Trigger, Line 26 Error converting data type varchar to numeric.
Surprisingly enough both my variables are varchar (50) Any ideas why this is happening?
Hi Prit,
The error message claims to stem from a procedure called "Part_Trigger".
Unless you have a very funny naming scheme, this procedure is actually a
trigger, and it's probably a trigger that fires on updates to the table
you are handling.
I'd suggest you find the code for the trigger and check it for the cause
of this error. Start looking near line 26 (see error message). Post the
trigger's code here, along with the CREATE TABLE statement for the table,
if you can't find the error.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Thanks hugo
Got it to work. There was a problem with the trigger. It was updating a
table which did not have the updated design of this table. I updated
the table and it worked like a charm. :)
Prit This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim |
last post by:
Hi
I want to be able to split the contents of a text field into two or maybe
three columns. The text field contains text AND HTML mark-up.
My initial thought was to find the middle character...
|
by: SL_McManus |
last post by:
Hi All;
I am fairly new to Perl. I have a file with close to 3000 lines
that I would like to split out in a certain way. I would like to put
the record type starting in column 1 for 2 spaces,...
|
by: Stephen Matthews |
last post by:
Help please
i have a file which im importing, however it is a single column, the
data looks like
C8517673505
N7062175
C8517673516
N7062178
C8517673527
|
by: Dave |
last post by:
Is there a way to divide a datagrid into "newspaper" style columns so that
column 1 would have rows 1-10, column two would have rows 11-20 etc?
Thanks, Dave.
|
by: heckstein |
last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
|
by: ashok |
last post by:
Hi,
I need a function that will divide text from mysql in 2 parts, so that I
can display first half in one column and second half in second column.
I can't find what function will do this job....
|
by: Dscar |
last post by:
Hi, I am a beginner in ACCESS, I've imported data into access, and then realized that I need to split the information in one of my columns into 2 columns. the information looks like this:...
|
by: Gilberto |
last post by:
Hello,
I have a couple of forms using the code to FIND AS YOU TYPE from Allen Browne (http://allenbrowne.com/AppFindAsUType.html). It worked PERFECTLY until yesterday when i splitted the db into...
|
by: chinni0719 |
last post by:
Hi I need to split the string which looks like
n.col1 , b.col1 , n.col2 , b.col2, n.col3 , b.col3 , b.col4 , n.col4 , b.col5,n.col5
n.col1,n.col2 are columns
these are present in...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |