So I am working on editing an existing stored procedure on a SQL server(2008 R2). I am running into some issues though due to my entry level knowledge of SQL. The issue is that the requirements for the report this generates have changed and the value of a field has changed from 2 to 3. The field length on the report was changed by the previous user, but they never accounted for instances where the data in the field only equals 2 characters. I.E. 20 or 03 instead of 100. This is causing the report to generate the values as such: '03 XX' instead of 003XX this is a problem because the system that receives this reads it from right to left so it will see these Null values and reject the whole report.
What I want to do is change the existing SET statement to a conditional statement that adds a padding '0' when the field value is only 2 char in length.
what I have currently is this:
SET @SupplyQuan = ISNULL((SELECT Unit FROM dbo.Supplyvalue(@UserID)
WHERE Number = 3),'')
What I need is a statement that reads similar to the following. The term I am having trouble with is the “Charactervalue”. I cannot find the SQL term for the value of a “cell” or field. I was thinking possibly “Columnvalue”, but that doesn’t seem to be correct. I am sure the answer is a very elementary one and I am probably overthinking this. Here is the code.
SET @SupplyQuan = ISNULL((SELECT Unit FROM dbo.Supplyvalue(@UserID)
WHERE Number = 3),'') IF “Charactervalue=3” ELSE IF “Charactervalue=2” THEN
SET @SupplyQuan = ISNULL('0'+(SELECT Unit FROM dbo.Supplyvalue(@UserID)
WHERE Number = 3),'')