varbinary in databricks

Shambhu Rai 1,411 Reputation points
2024-01-03T14:34:32.49+00:00

Hi Expert,

how we can convert below code into databricks notebook

Convert(Decimal(9,2),Convert(varbinary(4),substring(ac.at_desc,9,4))*1/100.00) as 'test'

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,442 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 23,290 Reputation points Moderator
    2024-01-03T15:55:48.69+00:00

    Thanks for posting your question in the Microsoft Q&A forum.
    With Spark DataFrame API, you can do as following:

    your_dataframe.withColumn(
        'test',
        (col('at_desc').substr(9, 4).cast('binary') * 1 / 100.00).cast('decimal(9,2)')
    )
    

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.