Solved

Query Help

Posted on 2011-02-22
5
212 Views
Last Modified: 2012-05-11
Hello experts:

I have a table called dbo.hard_i  in this table I have these columns:

Column Name               Data Type               Maximum Length
-------------------                ---------------              -------------------------
bhrd_q1                          float                       NULL                
rchrd_q1                         float                       NULL
hd_11                             float                       NULL

I need to select bhrd_q1  and rchrd_q1  and if these columns IS NOT NULL than I need to move to
hd_11.

How would this be written in a query format?

Thank you for your help

0
Comment
Question by:algotube
  • 3
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 125 total points
ID: 34952935
I'm not sure what you need to move to 'hd_11', but the query would be something like this:

update dbo.hard_i set hd_11 = < the column to move >
where bhrd_1 is not null and rchrd_q1 is not null

Open in new window


0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 125 total points
ID: 34953103
try these:

update dbo.hard_i
set hd_11 = isnull(bhrd_1, isnull(rchrd_q1,hd_11))

or

update dbo.hard_i
set hd_11 = isnull(bhrd_1, rchrd_q1)
where isnull(bhrd_1, rchrd_q1) is not null

or

update dbo.hard_i
set hd_11 = isnull(bhrd_1, rchrd_q1)
where bhrd_1 is not null or rchrd_q1 is not null
0
 

Author Comment

by:algotube
ID: 34953300
wdosanjos thank you for your reply very much appreciated.

I ran this query

USE Algoma_Lab_History
GO
SELECT bhrd_q1,rchrd_q1
FROM dbo.hard_i

bhrd_q1 rchrd_q1
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
399    NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
372    NULL
NULL  NULL
NULL  NULL
NULL  NULL

If the column does not contain a NULL like bhrd_q1  399 than I need to move it to hd_11. Same thing with rchrd_q1 if it does not contain a NULL than move it.


So I guess I could do this:

update dbo.hard_i set hd_11 = bhrd_1
where bhrd_1 is not null

and

update dbo.hard_i set hd_11 = rchrd_q1
where rchrd_q1 is not null

Thanks
0
 

Author Comment

by:algotube
ID: 34953318
HainKurt:,

Sorry just seen your reply............ I will take a look.........thanks
0
 

Author Closing Comment

by:algotube
ID: 34954812
Just wanted to say thank you to both of you today for helping very much appreciated. Have a great day.. :-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SHOWPLAN permission denied in database 'AdventureWorks'. 13 99
execute a MS SQL script as a schedule SQL job 72 128
Not selecting duplicate data 6 52
SQL Error - Query 6 24
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question