?
Solved

SQL Sever Query

Posted on 2014-08-20
2
Medium Priority
?
138 Views
Last Modified: 2014-08-20
I have two columns DATEUNIT and NUMOFDATE

The data shown in these columns varies, example
DATEUNIT         NUMOFDATE
W                        4
M                        3
Y                          1

W = Weekly
M = Monthly
Y = Yearly

I would like to have all the data shown in Weeks
I am looking for a query that I can run in the SQL Sever that will change the NUMOFDATE values to weeks dependant upon the current DATEUNIT
ie where is shows 1 year to 52 week, 2 years to 104 weeks

So the example above would show
DATEUNIT         NUMOFDATE
W                        4
W                        13
W                        52

Gordon
0
Comment
Question by:GiaHughes
2 Comments
 
LVL 53

Accepted Solution

by:
Vitor Montalvão earned 2000 total points
ID: 40272243
Assuming that a month have 4 weeks, this might be something similar for what you are looking for:

UPDATE YourTableNameHere
SET DATEUNIT='W',
        NUMOFDATE=NUMOFDATE*4
WHERE DATEUNIT='M'

UPDATE YourTableNameHere
SET DATEUNIT='W',
        NUMOFDATE=NUMOFDATE*52
WHERE DATEUNIT='Y'

Open in new window

0
 

Author Closing Comment

by:GiaHughes
ID: 40272306
Good quick response
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

840 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