Skip to content Skip to sidebar Skip to footer

Variables In T-sql

I have only 1 column in my table, in this table there are inputs like 990x70, 980x50. I need the values left and right of the 'x' to calculate inches of these 2 values. With this c

Solution 1:

Now, admittedly, I'm not totally clear on what you're asking. But it sounds like something like this should work:

SELECTCONVERT(NUMERIC(18,1), SUBSTRING([Values], CHARINDEX('x', [Values]) +1, LEN([Values]))) /2.54,
       CONVERT(NUMERIC(18,1), SUBSTRING([Values], 1, CHARINDEX('x', [Values]) -1)) /2.54FROM myTable

That should just do the same thing as you're doing, but without any of the variables (which are, in your usage, inherently one-dimensional).

Solution 2:

If you must use variables, start with this:

declare@Delimitervarchar(1) 
declare@CMtoInchesDECIMAL(19,2)

Set@delimiter='x'Set@CMtoInches=2.54

and see if you can work out how to integrate it into Matthew's code.

Post a Comment for "Variables In T-sql"