Is this possible to store the decimal type value in number column. 1/12 will be 0.083 and wants to store that in that column. create table test(number1 int,number2 int,number float) insert into test …
Tag: sql-server
Select by code and if there is no result select any other
Imagine there are some table with some data: id | code | name —————- 1 | 0001 | qwer 2 | 0002 | rtyu 3 | 0003 | asdf There can be only one record with code == 0002. Also it may be absent….
Split string value and use in INSERT and UPDATE command
I Implemented a small ERP system for our kitchen. The system is used to track our groceries, so it contains the goods (referred as food) with its name and UPC code. Over the time the names and upcs started to overlap and creating a data problem. In a first attempt we started to add the manufacturer into the n…
My sums are way too huge, is it not possible to do them all at once?
I have a table with colleague info, including their IDs, and a separate table with transaction data (such as revenue). In the transaction table, there are three fields (code1, code2, code3), they could be blank, or have colleague IDs, etc. I have no control over these tables. I am trying to accumulate some su…
Pivoting a string from a table function in different columns
I have a task to create a table function that receives a string and sorts it into different columns. The string itself may vary, but the columns are supposed to be the same always. The string is: ‘100^TEst¬200^TEst2¬300^Test3’, but for example if I add “¬400^Test4” that should be in th…
Facing issue while writing SQL in pyspark
I am trying to convert below SQL code to pyspark. Can someone please help me Here, util, count, procs are column names. while coding in pyspark, i can create a new column ‘col’ like this: Answer You can use when for doing the equivalent of update:
Arithmetic overflow error while converting varchar to decimal datatype
I am trying to convert varchar(14) to Decimal(14,2). My code is something like I am only getting Arithmetic overflow error message when the value of @varchar_variable is large (like ‘10000000000189’) Why am I getting this error message for larger values ? Are values like 10000000000189 out of rang…
Query on how to replace numerical data from a string/column
I have values in my column as below. Can anyone help me with how to replace any numeric data present in a column or string to blank using SQL Server query? Below is the column data. How do I replace the numbers to blank and display only underscores. Answer You could approach this by counting the number of und…
Stored Procedure not working with variables
I have a stored procedure as follows: When I run the above by passing the search variable as 04029125070527 I get no results. But if I edit my stored procedure as follows, I get a result. The only difference is in the above I’m trying to send the variable and in the second its hard coded (not what I wan…
SQL Update Multiple columns with counts
We currently have SQL update statements that works for our needs and updates the tbl_rprt table. Below are some of the update queries, there are several others like them. I was wondering if there was another way to get this done, maybe combining all of them into one SQL statement. #tbl_rprt is a report of all…