# 0 values after casting varchar(50) to float in named query

**URL:** <https://forum.inductiveautomation.com/t/0-values-after-casting-varchar-50-to-float-in-named-query/92317>\
**Category:** Ignition\
**Tags:** perspective, namedqueries\
**Created:** [June 25, 2024, 8:41am UTC](https://forum.inductiveautomation.com/t/0-values-after-casting-varchar-50-to-float-in-named-query/92317 "2024-06-25T08:41:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafal\_Samoraj](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Rafal\_Samoraj](https://forum.inductiveautomation.com/u/Rafal_Samoraj)\
**Post date:** [June 25, 2024, 8:41am UTC](https://forum.inductiveautomation.com/t/0-values-after-casting-varchar-50-to-float-in-named-query/92317/1 "2024-06-25T08:41:24Z")

</div>

Hello,  
In my named query I casted column ExternalLeakTestBackgroundResultmbarls which is varchar(50) to float. My column contain scientific notation of values.

In SSMS it ok but in Ignition don`t.

My named query is:

```python
SELECT 
	TimeStamp,
	[ExternalLeakTestBackgroundResultmbarls],
	CAST(REPLACE([ExternalLeakTestBackgroundResultmbarls], ',' , '.') AS FLOAT) AS 'CASTED TO FLOAT'
FROM 
	[SYS10064_X20].[dbo].[Result]
WHERE
	TimeStamp > '2024-06-24' and TimeStamp < '2024-06-25';

```

In SSMS it looks like that:

![SSMS](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/4/2429be0427acb2bee84d8109de7b1e23cc72ca8a.jpeg)

and It`s fine but, in Ignition it looks like that:

 ![IGNI](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0dab41835c3fb2269f127fb3f60373034b50cd74.jpeg)

Can anyone solve this?

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [June 25, 2024, 8:46am UTC](https://forum.inductiveautomation.com/t/0-values-after-casting-varchar-50-to-float-in-named-query/92317/2 "2024-06-25T08:46:25Z")

</div>

You should try testing it in scripting. I don't know if the query previewer can show such small numbers.

Try the following code in your console. runNamedQuery needs to be filled in.

```python
def printDataset(data):
	"""
	Prints the dataset or pyDataset pretty in a console log
	Args:
		data (dataset or pyDataset)
	returns nothing, but does print some info
	"""
	if data and data.rowCount > 0:
		# Determine the maximum width of each column
		columnWidths = []
		for colIndex in range(data.columnCount):
			columnName = data.getColumnName(colIndex)
			maxWidth = len(columnName)
			for rowIndex in range(data.rowCount):
				value = str(data.getValueAt(rowIndex, colIndex))
				maxWidth = max(maxWidth, len(value))
			columnWidths.append(maxWidth)
	
		# Print the header row
		headerRow = ""
		for colIndex in range(data.columnCount):
			columnName = data.getColumnName(colIndex)
			headerRow += columnName.ljust(columnWidths[colIndex] + 2)
		print(headerRow)
	
		# Print a separator
		print('-' * len(headerRow))
	
		# Print the data rows
		for rowIndex in range(data.rowCount):
			rowStr = ""
			for colIndex in range(data.columnCount):
				value = str(data.getValueAt(rowIndex, colIndex))
				rowStr += value.ljust(columnWidths[colIndex] + 2)
			print(rowStr)
	else:
		print("The dataset is empty.")
		return

dataset = system.db.runNamedQuery("YOURPATH")
printDataset(dataset)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 25, 2024, 9:46am UTC](https://forum.inductiveautomation.com/t/0-values-after-casting-varchar-50-to-float-in-named-query/92317/3 "2024-06-25T09:46:47Z")

</div>

You probably shouldn't be storing those as strings in the first place.  
If there's anything you can do about this, I'd suggest trying one of these:

> **[decimal and numeric (Transact-SQL) - SQL Server](https://learn.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql?view=sql-server-ver16)**
>
> Transact-SQL reference for the decimal and numeric data types. Decimal and numeric are synonyms for numeric data types that have a fixed precision and scale.
