Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT $ (dollar sign)

I have good experience in SQL Server, But suddenly I discovered this strange SELECT command

SELECT $  

or

SELECT $ FROM tableName 

All the time it returns zero scalar value (0.00), or a new column with all values of 0.00

What is that?

like image 530
Hussein Fawzy Avatar asked May 22 '15 22:05

Hussein Fawzy


People also ask

How do you do a dollar sign in SQL?

4.1.A dollar sign ($) followed by digits is used to represent a positional parameter in the body of a function definition or a prepared statement.

How do I type the dollar sign symbol?

Type Dollar Symbol in Windows In Windows, use alt + 0036 keys on the number pad to type $ symbol. Only on Word documents, use 0024 + alt + x keys to type $. You can also use Character Map or Symbols utilities to insert the symbol.

What does '$' do in JavaScript?

The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

What select * means?

SELECT == It orders the computer to include or select each content from the database name(table ) . (*) == means all {till here code means include all from the database.} FROM == It refers from where we have to select the data.

What does the dollar sign mean in Excel?

When you use a $ sign before the cell reference (such as $C$2), you’re telling Excel to keep referring to cell C3 even when you copy and paste the formula. Now you can use the dollar ($) sign in three different ways, which means that there are three types of references on Excel.

How to type the dollar sign on a keyboard?

However, if copy and paste aren’t what you are looking for, and you cannot also find or type the ($) Symbol key on your keyboard, continue reading below on how you can type the Dollar Sign using some shortcuts. 1. Using the Dollar Symbol key on the keyboard 2. Using the Dollar Symbol Alt Code (Windows Only) 3.

How do you add a dollar sign to an absolute reference?

First, put the cursor beside a cell reference in the formula or select that cell reference in the formula bar. Alternatively, you can double-click on the cell containing the formula to insert the dollar sign there. Then, press F4 on your keyboard. It will insert the dollar sign in the formula making the cell reference an absolute reference.

How do you add a dollar sign to a formula?

Alternatively, you can double-click on the cell containing the formula to insert the dollar sign there. Then, press F4 on your keyboard. It will insert the dollar sign in the formula making the cell reference an absolute reference. Next, press F4 It will change the reference to a mixed reference making the row fixed but keeping the column relative.


2 Answers

When SQL Server comes across your $ sign, it automatically converts it into a money data type. Because you don't have an explicit value after the dollar sign, SQL Server is assuming 0.00. From MSDN:

When converting to money or smallmoney, integers are assumed to be monetary units. For example, the integer value of 4 is converted to the money equivalent of 4 dollars (for us_english, the default language). Numbers to the right of the decimal in floating-point values are rounded to four decimal places for money values. Expressions of data types char or varchar that are being converted to an integer data type must consist only of digits and an optional plus or minus sign (+ or -). Leading blanks are ignored. Expressions of data types char or varchar converted to money can also include an optional decimal point and leading dollar sign ($).

like image 152
Icemanind Avatar answered Oct 04 '22 05:10

Icemanind


After a little messing around, I've figured since this happens no matter what currency symbol is used, SQL server is implying that the field is a currency field.

If you add numbers after the currency symbol, in this case a dollar so:

SELECT $4 

SQL server will return 4.00

So SQL Server is taking the use of $ and assuming we want to create a field with the MONEY datatype and as we haven't entered a value after the currency symbol, SQL Server assumes the value is 0, though in my opinion this should return NULL.

like image 43
Alec. Avatar answered Oct 04 '22 03:10

Alec.