Convert number to varchar using to_varchar with leading zeros in Snowflake - snowflake-cloud-data-platform

In Snowflake there is a number column storing values like: 8,123,456. I am struggling determining how to structure select statement to return a value like: 00008123456.
In SQL SERVER you can do something like this:
right(replicate('0', 11) + convert(varchar(11), job_no), 11) AS job_no
I understand Snowflake to_varchar function can be used, but not sure how to structure like in SQL Server.

Just add a format string on to_varchar():
select to_varchar(8123456, '00000000000');

Give it try with: lpad(to_char(nos),11,0)
More examples & details: https://docs.snowflake.com/en/sql-reference/functions/lpad.html#examples

a solution provided by Greg Pavlik saved me.
I just switched from DB2 to Snowflake.
So, TO_VARCHAR( <numeric_expr> [, '<format>' ] ) worked.

Related

SQL Server Select LIKE Regex Equivalent to '?' or '\\s*'

I have a short question is there an equivalent to ? in SQL Server SELECT LIKE regex?
I try to select data from table in SQL Server 2012. Example data from column
...
<SOMETHING>
<UNINTERESTING>test</UNINTERESTING>
<INTERESTING>searchedString</INTERESTING>
<SOMEMORE>
<PROBLEMHERE>searchedString</PROBLEMHERE>
</SOMEMORE>
...
or
...
<SOMETHING>
<UNINTERESSTING>test</UNINTERESSTING>
<INTERESING>searchedString but nevertheless wrong</INTERESTING>
<SOMEMORE>
<PROBLEMHERE>searchedString</PROBLEMHERE>
</SOMEMORE>
...
I can select these with
LIKE '%<INTERESING>searchedString</INTERESTING>%'
everything works fine, but it is possible that the value between <INTERESTING> ends sometimes with one or more spaces
e.g.
<INTERESING>searchedString </INTERESTING>
<INTERESING>searchedString </INTERESTING>
If I try to select with %, then I got rows, where the search string is found but not between interesting, or between two interestings, or I get the wrong rows like
<INTERESING>searchedString but nevertheless wrong</INTERESTING>
I tried to select with _, %, [ ] but nothing of them get me the correct rows.
Is there an equivalent in SQL Server LIKE regex for ? (none or one-time)
or anything like \s* (whitespaces, can be none, one or more-times)
Thanks in advance
best regards
Since you problem is spaces... just replace / remove those and your like statement should work and you can avoid other parsing and worrying about REGEX all together.
where replace(column,' ','') like'%<INTERESING>searchedString</INTERESTING>%'
If you expect TAB or NEWLINE then use replace and CHAR(10) and CHAR(13)
where replace(replace(replace(column,' ',''),char(10),''),char(13),'') like'%<INTERESING>searchedString</INTERESTING>%'
Is there an equivalent in SQL Like Regex
No. You should use SQL Server's XQuery to parse the XML and extract the XML Element values, and then use LIKE for examining the element value.

Calling oracle package from SSRS

I want to send the date range and employee ids from SSRS to Oracle package. Does anyone knows how to do it? Even if i try to declare an oracle package with three in parameters from_date, to_date and employee_id it works fine with one employee id. But fails if i select multiple employees in SSRS web interface saying wrong number of parameters. Does anyone know how to handle this?
Normally with SQL and SSRS you would do something like
Select * From Table where Table.Field in #Param
Oracle is different of course and depends on the Connection Type you are using.
ODBC connection you would use something like:
Select * From Table where Table.Field = ?
Order of the parameters is important here so be careful.
OLEDB connection you would use something like:
Select * From Table where Table.Field = :Param
However, none of the above work with multi selecting of the Parameters. You could do this:
=”Select * From Table where Table.Field in (‘” + Join(Parameters!parameter.Value,”‘, ‘”) + “‘)”
or
=”Select * From Table where Table.Field in(” + Join(Parameters!parameter.Value,”, “) + “)” if the values or your field is only numeric.
Here are a couple of good articles that you can look at. It has a better explanation than I can give personally without more information; Details of your Oracle Environment, Connection Type, etc.
Quick Reference:
Be sure your Oracle version is 9 or greater, none of this works on
versions 8 or older.
When using parameters with Oracle, use a : instead of an # sign –
:param instead of #param.
Add an ‘ALL’ option to your datasets that supply values for
multivalued drop down parameters.
Check for the ALL in your where clause by using “where ( field1 in (
:prmField1 ) or ‘ALL’ in ( :prmField1 ) )” syntax.
You can execute your query from the dataset window, but can only
supply 1 value. However that value can be ‘ALL’.
Educate your users on ‘ALL’ versus ‘(select all)’ .
Another good article about Multiple Parameters in SSRS with Oracle: Davos Collective Which is referenced in the top portion.
Hope this helps!

How to use extractvalue in SQL Server

I am trying to convert my Oracle query to SQL Server. The query shown below is causing some difficulty when trying to convert EXTRACTVALUE, XMLSEQUENCE, XMLTYPE functions.
Can anyone help me learn how to convert these to SQL Server?
EXTRACTVALUE(COLUMN_VALUE, 'pipeline/#name') NAME
FROM TABLE (SELECT XMLSEQUENCE(XMLTYPE(MESSAGE).EXTRACT('processEngine'))
FROM NMS_MESSAGES WHERE OBJECT_CODE='pe_monitor' AND ID=#WHERE:PARAM:USER_DEF:INTEGER:PARAM_PROCESS_ENGINE#)) INSTANCENAME
,(SELECT EXTRACTVALUE(COLUMN_VALUE, 'processEngine/#id') FROM TABLE (SELECT XMLSEQUENCE(XMLTYPE(MESSAGE).EXTRACT('processEngine'))
FROM NMS_MESSAGES WHERE OBJECT_CODE='pe_monitor' )) ENGINE_ID
Thanks in advance.
Think about XQuery. As I See that EXTRACTVALUE seems like #xml.values('(#node/#attr)[1]','type') and EXTRACT is #xml.nodes('path/path/path')
If know structure of xml that you ought to parse exactly than you will convert this query without any problems.

Wingding chars in sql server 2005

In a winforms application i 'm storing one Wingdings char in a SQL Server 2005 field of type NVARCHAR(1).
Storing, retrieving and showing up this char in a control works fine.
The problem i'm facing is this: how to search for records which have a specific wingding char value: for example
Select * from table where FieldWithWingding = valueOfLeftArrowChar
How to achieve this?
Thanks in advance
Wingdings is a font! Fonts give a special appearance to characters in a given character set. The left-arrow is therefore a character. Look it up in start->all programs->Accessories->System tools->Character map
Your select will be something like:
Select * from table where FieldWithWingding = 'ß'
Igor pointed me into the correct direction:
it's actually
Select * from table where FieldWithWingding = N'ß'
Works fine!
Thank you everybody!
Try this: select Unicode(N'ß'), Nchar(Unicode(N'ß'))
Use #filter nvarchar(1) or nchar(1) data types

How to show decimal zeroes for a number in SQL Server

I am pulling the following numbers from MS SQL Server:
345
345.6
345.67
How do I pull them so that they look like the following:
345.00
345.60
345.67
What datatype should they be stored as and what is the magic function to pull them?
Thank you.
You can use a cast function. Since you are pulling out values of a table, you would be using a select and some thing like the following can be used-
Select CAST(value AS DECIMAL(5,2)) from table
I hope that is what you are looking for.
cheers

Resources