When using TSql to check if a varchar is null or is empty we can remember:
- A nullable varchar is
1. not null when store a string or an empty string;
2. null only when not initialized, even with an empty string.
update fied1 = 'A string', field2 = '', field3 = null
We have:
Select * from table where field1 is null (0 row)
Select * from table where field2 is null (0 row)
Select * from table where field3 is null (1 row)
Select * from table where field1 = '' (0 row)
Select * from table where field2 = '' (1 row*)
Select * from table where field3 = '' (0 row)
Select * from table where (field2 = '' and field2 is null) (0 row)
Select * from table where (field2 = '' and field2 is NOT null) (1 row**)
Well, the objective is to pay attention to our predicates of where clause, because sometimes some results are not expected when selecting empty strings
* this can be true for any amount of spaces
** pay special attention to this predicates working together
/*------------------------
Select * from select_varchar where field1 is null
Select * from select_varchar where field2 is null
Select * from select_varchar where field3 is null
Select * from select_varchar where field1 = ''
Select * from select_varchar where field2 = ''
Select * from select_varchar where field3 = ''
Select * from select_varchar where (field2 = '' and field2 is null)
Select * from select_varchar where (field2 = '' and field2 is NOT null)
------------------------*/
field1 field2 field3
---------- ---------- ----------
(0 row(s) affected)
field1 field2 field3
---------- ---------- ----------
(0 row(s) affected)
field1 field2 field3
---------- ---------- ----------
A String NULL
(1 row(s) affected)
field1 field2 field3
---------- ---------- ----------
(0 row(s) affected)
field1 field2 field3
---------- ---------- ----------
A String NULL
(1 row(s) affected)
field1 field2 field3
---------- ---------- ----------
(0 row(s) affected)
field1 field2 field3
---------- ---------- ----------
(0 row(s) affected)
field1 field2 field3
---------- ---------- ----------
A String NULL
(1 row(s) affected)
sexta-feira, 19 de setembro de 2014
quarta-feira, 3 de setembro de 2014
TSQL RowNum from Oracle equivalent, and the PhysLoc column
I was looking for the Row_Number() sintax on
Internet:
SELECT
*, ROW_NUMBER() OVER (ORDER BY [column name]) as rowNum
FROM
[table name]
order
by ROW_NUMBER() OVER (ORDER BY [column name])
And
I have found this, as a gift:
SELECT id, %%PhysLoc%% from dbo.A ORDER BY %%PhysLoc%%;
In
Oracle we used to use something like that to improve performance in updates,
specially in non-normalized tables where PK was not set yet, and sometimes
better than a PK index.
Assinar:
Postagens (Atom)