I have a table similar to this: -
Id Number Street Address
-
--- ------ ------ -----------
-
100 NULL NULL 234 Main St
-
101 NULL NULL 516 W Oak St
-
I want the end result to look like this: -
Id Number Street Address
-
--- ------ ------ -----------
-
100 234 Main St 234 Main St
-
101 516 W Oak St 516 W Oak St
-
How can I do this in SQL? I understand I could do it with scripting but would prefer a SQL statement.
Thanks!
K
Try this out: -
DECLARE @t as TABLE(StreetNumber int, StreetName char(15), rData varchar(20))
-
-
INSERT INTO @t VALUES( NULL,NULL,'123 main st')
-
INSERT INTO @t VALUES( NULL,NULL,'421 Cherry ln')
-
INSERT INTO @t VALUES( NULL,NULL,'544 Peach st')
-
-
Update @t
-
SET StreetNumber = convert(INT,left(rData,charindex(' ',rData)-1)),
-
StreetName = right(rData,len(rData)-charindex(' ',rData))
-
-
SELECT * FROM @t
-
3 1420
Where do you take the Number and Street values from?
Are they from another table? If yes, you may use INNER JOIN
Try this out: -
DECLARE @t as TABLE(StreetNumber int, StreetName char(15), rData varchar(20))
-
-
INSERT INTO @t VALUES( NULL,NULL,'123 main st')
-
INSERT INTO @t VALUES( NULL,NULL,'421 Cherry ln')
-
INSERT INTO @t VALUES( NULL,NULL,'544 Peach st')
-
-
Update @t
-
SET StreetNumber = convert(INT,left(rData,charindex(' ',rData)-1)),
-
StreetName = right(rData,len(rData)-charindex(' ',rData))
-
-
SELECT * FROM @t
-
@b0010100
Thanks b0010100! That does the trick.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: el_sherif |
last post by:
how to update and retrieve ntext fields in my asp code
PLEASE HELP
|
by: middletree |
last post by:
I have a table which has a datetime field for when a row in this one table
(Ticket) was created. This is for trouble tickets for a help desk. After a
ticket has been created, any additions to that...
|
by: mark.reichman |
last post by:
First off.. Thanks to Grant Wagner for help in a previous thread
related to this one.
I am at a total loss... I have multiple fields in a form with the
same name. Lets call the fields with the...
|
by: ruthboaz |
last post by:
Hi,
I am exporting a table with data to an excel file.. Some fields are empty in the exported file while the others and the key field, has values.
The empty field(s) in excel, will be entered...
|
by: voroojak |
last post by:
Hi
How can i put save record and next record in one button.
in my save record i put the calculation of the text boxes. i have a total field that the sum of the other field is in there and it wil be...
|
by: Kosal |
last post by:
Dear Sir/Madam
I would like to Update record to last record in database that unkown last record
please advice.
thanks
Best Regard
|
by: pzh20 |
last post by:
I have an unbound form/subform where I populate a combo box on the main form, and using the onchange event, display fields from a table in a datasheet subform.
I want to add a new record via the...
|
by: Trexsuz |
last post by:
I am creating a subreport with multiple records possible. I am wanting one of 2 fields (A and B) to be visible based on the inormation in another field(C Yes or No). The first record has a Yes in C...
|
by: steve75043 |
last post by:
Hello I hope someone can help with this. I need to subtract dates in current record from previous record for the current store.
The key fields in the form are customer, store number and date picked...
|
by: TheSmileyCoder |
last post by:
I have a report with some data on the left side, in fields that can grow, and some fields on the right side. My problem is that when the lefthand fields do grow, they "push" down my righthand fields....
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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: 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: 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...
| |