(
@CompanyID NVARCHAR(36),
@DivisionID NVARCHAR(36),
@DepartmentID NVARCHAR(36),
@ItemID NVARCHAR(36),
@OrderNo NVARCHAR(36),
@LineNo NVARCHAR(36),
@TAllotedQty Numeric,
@EmployeeID NVARCHAR(36),
@Trndate datetime
)
AS
BEGIN
By default iam passing 12 char itemid as parameter...
Here iam selecting the itemid from InventoryLedger -if it is 8 char than this query should be executed
IF EXISTS(SELECT ItemID FROM InventoryLedger WHERE TransDate=@Trndate AND ItemID=@ItemID AND ILLineNumber =@LineNo AND TransNumber=@OrderNo AND TransactionType='Production' AND CompanyID=@CompanyID AND DivisionID= @DivisionID AND DepartmentID=@DepartmentID)
BEGIN
DECLARE @Qty INT
select @Qty =QUANTITY from inventoryledger WHERE TransDate=@Trndate AND ItemID=@ItemID AND ILLineNumber =@LineNo AND TransNumber=@OrderNo AND TransactionType='Production' AND CompanyID=@CompanyID AND DivisionID= @DivisionID AND DepartmentID=@DepartmentID
select qtyonhand=qtyonhand+@Qty from InventoryByWareHouse where ItemID=@ItemID
END
Here iam selecting the itemid from InventoryLedger -if it is 12 char than this query should be executed(both queries are same)
IF EXISTS(SELECT ItemID FROM InventoryLedger WHERE TransDate=@Trndate AND ItemID=@ItemID AND ILLineNumber =@LineNo AND TransNumber=@OrderNo AND TransactionType='Production' AND CompanyID=@CompanyID AND DivisionID= @DivisionID AND DepartmentID=@DepartmentID)
BEGIN
DECLARE @Qty INT
select @Qty =QUANTITY from inventoryledger WHERE TransDate=@Trndate AND ItemID=@ItemID AND ILLineNumber =@LineNo AND TransNumber=@OrderNo AND TransactionType='Production' AND CompanyID=@CompanyID AND DivisionID= @DivisionID AND DepartmentID=@DepartmentID
select qtyonhand=qtyonhand+@Qty from InventoryByWareHouse where ItemID=@ItemID
END
#1 This stored procedure can be used to search and replace substring in the char, nchar, varchar and nvarchar columns in all tables in the current database. You should pass the text value to search and the text value to replace. So, to replace all char, nchar, varchar and nvarchar columns which contain the substring 'John' with the substring 'Bill', you can use the following (in comparison with the SetTbColValues stored procedure, this stored procedure replace only substring, not the entire column's value):
I add some records to two tables after createing operation completed.
Then i use dbcc page command to oversee the structures of data page in two tables. I found some interest things: The rows in two tabes take up same space:9 bytes
You can see the "9" on top of the data, for example:Slot 0, Offset 0x60, Length 9, DumpStyle BYTE or calculate from the offset array
I am importing a table where I need to convert a char(1) with thevalues of 't' or 'f' into a bit field with valies of 1 or 0. Is therea built-in function that does that? I've been searching, but I can'tfind an answer.
Hi, I am trying to write some simple SQL to join two fields within a table, the primary key is an int and the other field is a varchar. But i am receiving the error:'Conversion failed when converting the varchar value ',' to data type int.The SQL I am trying to use is:select game_no + ',' + team_name as matchfrom result Thanks
Does any body know of any performance implications of using 'varchar' data type against 'char'?
I have some columns that are using 'char' data type, but the data in them is not fixed length. So, to gain some disk space I am planning to change the data type to 'varchar'. But, I am concerned if there will be any performance de-gradation or any other implications of doing this.
I have recently inherited a database where all of the tables use varchar instead of chars for fields. Very , very few of these fields are involved in keys of even indices, but performance is an issue. I thought that I had read that varchars are worse for performance than chars when page splits may occur. Is this related to updates only, or does it matter?
I hv executed the following query in the Query Qnalyzer (Ofcourse I am Using SQL 2000 Enterprise Edition) and Surprisingly I am getting the Output as follows,
query:- select '5' + 10
Output:- 15
Can anybody please tell me, why it is happening like this? OR Did I miss any Configuration Parameter in the Server Settings?.
I have a table which will recieve and interface file to be loaded. All the fields are there except an account_id field which is a char(12), but the data is a number 000000000001, 000000000002, etc. These numbers are to be incremented by one. I understand how to write the process using a cursor to run through all the records and to increment them before loading. My question is the best way to get the max number in the existing table which is the char(12) , and icrement the number by one, but retain the leading zeroes I will need. Anyone had the pleasure of doing this providing input greatly appreciated.
I'm looking through some data in a third party application, trying to figure something out for a report. There is a char(1) column holding control characters that apparently effects the status of certain records, and whether they should appear on the report. I want to look at the integer value of those characters rather than the character representation, but I can't get it to work. I keep getting "Error converting data type varchar to numeric." I'm trying to do something like this: Code:
SELECT CONVERT(int, MyColumn) As IntValue FROM MyTable
I've tried every combination of cast and convert I can think of, as well as numeric data types other than int. There aren't that many distinct values, so I'm just going to do this manually, but I still want to know why it won't work, or what I'm doing wrong. Any thoughts?
I am new to MS SQL. One VB application that I need to maintain using it. There is one problem reported but I couldn't explain: one field is declared as Char (20), but the application seems able to insert a string with length even 30. There is no character truncatd when retrieved neither.
However, I cannot simulate the case in the MSSQL database manager. When I executed a SQL script to insert, I was simply not allowed to do so.
Any explanation to the sDid anyone encounter same thing before? Thanks for any hint.
Hi, This question may sound silly,but please comment. Please tell me a situation where char should be used and not varchar. Let us assume that we are dealing with non unicode characters. Well, I find varchar is always smarter than char, so why char? Thanks!! Rudra
i would like to know if there is an overhead in using VARCHAR when you use to store it...
a colleague of mine claims that if the field is defined to be VARCHAR the system creates and additional column DOUBLE/DECIMAL with storage size of 17/18bytes.
such that if the size of the varchar field is less than 30 it is better to be defined as CHAR instead.
please help me out here... i think there's something wrong with his statement, but i need concrete proof to it... a link to page or pdf file would be very much appreciated.
Used to know how to do this but am having no luck today. I have data coming in from a .txt file that gives me char strings for dates, e.g. 02242003 for Feb. 2, 2003.
Need to whomp this into small datetime with the whole convert/cast thing but I guess I've previously only gone the other way--smalldatetime to char.
I have one table that has a column 'amount' with datatype 'numeric(19,5)' I'm want to insert the data from this column into another column (in a different database) with this format: '00000000.00' as 'char' example: If in the first column I have 800.75864 I want to insert it in the other column as '00000800.75'
(1) Purely fractional numbers sometimes have the first zero removed. So "0.03875" is stored as ".03875" (2) Some numbers have trailing zeros added. So "70.7" is stored as "70.700000".
Can someone help how to overcome the formatting errors.
I'm extracting a char(2) field from a table that has a value of '1' and writing it to another table but want the output field to be padded with a zero. I have tried this below:
right('00' + isnull(Field1, ' '),2
but the output field comes out as '1 ' (that's 1 followed by a space). Does anyone have any idea how I can do this or please point out what I'm doing wrong in my 'right(' fucntion above. Thanks, Jeff
I'm scrambling to complete a project and ran into an int to char problem. I'm sure, in my haste, I'm doing something stupid. Here is an example of what I'm trying to do but it doesn't convert as expected. I want the SEQ_NBR2 value to convert from 4 to 0000004.
select right('0000000' + convert(char(7), isnull(a.SEQ_NBR2, 0.0)), 7) fromTXN_HEAD_837 a where a.file_auth_nbr = '1084472388468' anda.seq_nbr2 = 4 and a.sgmt_id2 = 'BHT'
I seem to recall many debates and articles about primary keys, but for the life of me, I can't seem to figure out what to do in what is probably be a very straight forward situation (below). Must be all the late nights lately impairing my common sense.
So, I've basically got a set of data where I want to extract a status field from the table design. I'll end up with two tables:
MainTable(Field1,Field2, ... ,FieldA ,StatusID) StatusTable(StatusID,Field1,Field2) [shouldn't be that big a table, actually]
It's a silly thing but... are there any significant reasons why I should choose int for my StatusID instead of char?
I seem to be under the impression that using arbitrary int numbers as the identifiers will yield better performance on joins; but from past experience, using arbitrary int numbers can be a bother to interpret the data. :P I've seen tables where they were so full of numeric codes, that I had to do multiple joins to the respective code tables to yield what each code meant (or what that particular row meant as a whole).
Of course, I don't mean to use an actual full description for my primary keys, but would it be so bad to use something like "N" (to indicate "normal")?
I have a Column called PostNr which is of type Char(4) I want to be able to Convert it to int How can I accomplish that in query analyser, I tried changing it in Ent Manager, it keeps timing out. I data in Post is in this format, does not contain illegal character just number
Greetings,I have a question. I work on some SQL2k/ASP.NET apps at work. Mypredacessor, who created the databases/tables seemed to have liked touse 'char' for all text fields. Is there a reason why he would havedone this over using varchar? It's a minor annoyance to always have toRTRIM data and it makes directly making changes to the database moreannoying (with all the pointless trailing spaces)?I usually use char for fixed string lengths, like state abbreviationsor something, and varchar for strings of unknown length.Is it a performance issue? Our database doesn't do much traffic, forthe most part.
I have data tables that include ZIP code, as char(5). The values looklike integers, but they are padded with leading zeroes to fill out 5characters, '00234'.There are SPs to look up data, with @Zip char(5) among the parameters.Some users call these with integer values, @Zip = 234, and SQL makesthe conversion. Is it necesary to add the leading zeroes in the SP --@Zip=RIGHT('00000'+@Zip,5) -- or would SQL find this match? (234 ='00234'). It looks like the conversion is to '234' and the matchfails.Thanks,Jim GeissmanCountrywide
HiI have a SQL database with approx., 90m rows. Within the tablethere several fields that are varchar 4. On a test server with approx.200k rows I converted those to char4.It showed that the database size shrunk by approx. 20 %, why I don'tunderstand.My question is would I get a performance improvement for selectqueries against those fields when they are char4 as opposed to varchar4 ?Thanks
Hi, In a report we have a couple of pie charts one for each category. for eg. if there are 3 categories red,blue and yellow there will be three pie charts. Now the data is shown to a particular user only if the user has access to a particular category. suppose while designing the report the pie charts are created in the order : chart - red chart - blue chart - yellow.
If a user has rights only on the yellow category, only one chart will be displayed and chart-red and chart-blue will be hidden. Now the problem is, on the report I get blank space before chart-yellow as chart-red and chart- blue are hidden. is there a way to position chart - yellow in place of chart-blue if chart-blue is hidden or position chart-yellow in place of chart -red if chart-red and chart- blue both are hidded?
Hi all,I have a column LateHours (Varchar). I want to put it in another table which has Latehours column in Decimal(4,2) Example = +04:33 Should be 4.33 (Only + values) Char to Decimal (4,2) Please Help me,Thanks,Janaka