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 wondering which way is the best way to store your numeric values. It probably doesnt matter, b/c you can always convert back and forth...but i'm just wondering what the best practice is i guess...
I have a report with a column which contains either a string such as "N/A" or a number such as 12. A user exports the report to Excel. In Excel the numbers are formatted as text.
I already tried to set the value as CDbl which returns error for the cells containing a string.
The requirement is to export the column to Excel with the numbers formatted as numbers and the strings such as "N/A' in the same column as string.
Why does M$ Query Analyzer display all numbers as positive, no matterwhether they are truly positive or negative ?I am having to cast each column to varchar to find out if there areany negative numbers being hidden from me :(I tried checking Tools/Options/Connections/Use Regional Settings bothon and off, stopping and restarting M$ Query Analyer in betwixt, butno improvement.Am I missing some other option somewhere ?
I have a table with a column ID of ContentID. The ID in that column is all NULLs. I need a way to change those nulls to a number. It does not matter what type of number it is as long as they are different. Can someone point me somewhere with a piece of T-SQL that I could use to do that. There are over 24000 rows so cursor change will not be very efficient.
( @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
I have an 'ID' column. I'm up to about ID number 40000, but not all are in use, so ID 4354 might not be in any row. I want a list of all numbers which aren't in use. I want to write something like this:
select [numbers from 0 to 40000] where <number> not in (select distinct id from mytable)
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'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