SQL Update Column [closed] - sql

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How do I grab the last character of a column and convert it to a number? Example: Column000000000017A000000000038B000000000431CNeed to change the last letter to the following if letter equals to:A=1B= 2C=3Results:1713824313

The ASCII value of A is 65. So you can translate C to 3 by subtracting 64 from its ASCII value.
select cast(
left(col1, len(col1) - 1) +
cast(ascii(upper(right(col1, 1))) - 64 as char(1))
as int)
from Table1
Live example at SQL Fiddle.

i think you need to use REPLACE function of SQL
http://msdn.microsoft.com/en-en/library/ms186862.aspx

Figured it out with the following SQL Statement. To change multiple criteria replace in one column, I used:
SELECT REPLACE(REPLACE(REPLACE(Prev_Month_Vol,'A','1'), 'B', '2'), 'C', '3')
FROM table1
Hope this helps out someone looking to do replace statements.

Related

What Does the SQL dash character do? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
In a SQL statement I am debugging, I found a - used in a way I don't recognize:
it appears in this SELECT statement between "Book_Balance" and "Participation_Lookups"
SELECT "LNIMPR"."Book_Balance" - "Participation_Lookups"."Participation Principal Assets" AS "C7"
FROM ...
What does the - do in the above context?
It is subtracting the two columns.
They must both be numeric values and in SQL to subtract you use the minus sign -.
If Book_balance is 100 and Participation Principal Assets is 25, then is it basically saying:
select 100 -25 as C7
from ...
This calculation is occurring for each row that is returned.
Numeric subtraction, as in 10 - 4 = 6

sql with an array [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Can this loop be done in sql ?
Dim ID(0 TO 2) as string
Dim number as string
ID="01"
ID="02"
For each number in ID
SELECT data FROM sheet1 WHERE data= number
next number
datatable:
data
01
01
02
03
04
This can be done using the IN predicate:
SELECT data FROM sheet1 WHERE data IN(1, 2);

how do i display the sum of a SQL query in HTML? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I tried to do this:
SELECT SUM(SUBTOTAL as TODAYSALES) FROM dbo.SALESORD_HDR where ORDERDATE >=41187
But the browser throws an exception about the sum function saying 'SUM' is not a recognized built-in function name.
Any ideas?
Doing a
SELECT SUM(SUBTOTAL) as TODAYSALES FROM ...
would work a lot better.
Your syntax seems off. It should be SELECT SUM(SUBTOTAL) AS TODAYSALES FROM dbo.SALESORD_HDR where ORDERDATE >= 41187
Aliases must be defined outside the expression they are targeting:
SELECT SUM(SUBTOTAL) as TODAYSALES FROM dbo.SALESORD_HDR where ORDERDATE >=41187

How do I add hours to the result of SQL Server's `GetDate()` function? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to add 2 hours to the result of getdate() in SQL SERVER. I know that I can add one day with:
select getdate() + 1
But how is this done when wanting to add on hours onto getdate()?
select dateadd(hour,2,getdate())
Select GETDATE() + (Convert(float,2)/Convert(float,24))
OR in other way
Select DateAdd(HH,2,Getdate())

How can you format a persisted column as a padded integer string [SQL Server 2008] [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What formula would I use in a persisted column so that I can add the two columns below together, the first must be padded to 5 characters:
ID (INT)
RefNum (STRING)
I went for format(ID,"00000") & RefNum, but it doesn't work, any ideas please?
You could use something like this:
ALTER TABLE dbo.YourTable
ADD FormattedColumn AS RIGHT('00000' + CAST(ID AS VARCHAR(5)), 5) + RefNum PERSISTED
Basically, convert the ID to a VARCHAR(5), prepend it with 00000 and then grab the five right-most characters.
SELECT RIGHT('00000' + CAST(ID AS VARCHAR(5)), 5) + RefNum