georgepatotk Posted March 11, 2004 Posted March 11, 2004 I have such fields in a Table StockNumber = int [primary] BranchCode = int [foreign] InvoiceNumber = Text [Normal data] I do as below but why why why??? "SELECT StockNumber, BranchNumber, COUNT(InvoiceNumber) FROM tblStock GROUP BY InvoiceNumber, StockNumber, BranchCode" How to make Text Group-able?? Please help me.. Quote George C.K. Low
Administrators PlausiblyDamp Posted March 11, 2004 Administrators Posted March 11, 2004 I have such fields in a Table StockNumber = int [primary] BranchCode = int [foreign] InvoiceNumber = Text [Normal data] I do as below but why why why??? "SELECT StockNumber, BranchNumber, COUNT(InvoiceNumber) FROM tblStock GROUP BY InvoiceNumber, StockNumber, BranchCode" How to make Text Group-able?? Please help me.. How large an InvoiceNumber do you use? a char/varchar can hold approx. 8K of text while the unicode variants (nchar/nvarchar) can hold approx 4K of text - are these not suitable. Text as a datatype is really a large binary field and can store up to 2G of data per field - it's this large storage capacity that prevents it's use in certain situations i.e. grouping, indexing etc. If I was you I'd rethink the choice of data type and also investigate to see if it has been used elsewhere in the data base. There are many reasons to avoid Text as a data type for smaller string based dataitems (indexing, potential performance issues, recoverability, issues with replication etc.) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted March 11, 2004 Author Posted March 11, 2004 for char = 4k of text. means how many characters? mind to tell?? Quote George C.K. Low
Administrators PlausiblyDamp Posted March 11, 2004 Administrators Posted March 11, 2004 1 byte per character for char/varchar, 2bytes per character for nchar/nvarchar. a char/varchar field can hold approx 8,000 characters while a nchar/nvarchar can hold approx. 4,000 characters. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted March 11, 2004 Author Posted March 11, 2004 1 byte per character for char/varchar, 2bytes per character for nchar/nvarchar. a char/varchar field can hold approx 8,000 characters while a nchar/nvarchar can hold approx. 4,000 characters. Thanks. I think I got to change my mind in choosing char instead of Text. SO, Char can be grouped in SQL? Quote George C.K. Low
Administrators PlausiblyDamp Posted March 11, 2004 Administrators Posted March 11, 2004 Thanks. I think I got to change my mind in choosing char instead of Text. SO, Char can be grouped in SQL? Certainly - it was why I suggested the change:D Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted March 11, 2004 Author Posted March 11, 2004 Thanks a lot. kiss kiss.... Quote George C.K. Low
*Experts* Nerseus Posted March 11, 2004 *Experts* Posted March 11, 2004 Why do you even need InvoiceNumber in that query? It looks like you're grouping by only two fields and just getting a count? Even if you wanted to ues "... COUNT(DISTINCT InvoiceNumber)", you still wouldn't need the InvoiceNumber in the GROUP BY. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
georgepatotk Posted March 12, 2004 Author Posted March 12, 2004 In my case, I want to show to the users the details in a datagrid. Databases Fiels: [tblStock_BRanch] : Stock_BranchNumber, StockNumber, BranchNumber, InvoiceNumber, and PurchaseDate [tblStock] : StockNumber, StockCode, StockCost [tblBranch] : BranchNumber, BranchCode, BranchDescription what i am doing here is: SELECT sb.StockNumber, COUNT(StockNumber) AS Unit, s.StockCode, sb.BranchNumber, s.BranchCode, sb.InvoiceNumber, sb.PurchasesDate FROM tblStock_Branch sb, tblStock s, tblBranch b WHERE s.StockNumber = sb.StockNumber AND b.BranchNumber = sb.BranchNumber GROUP BY sb.StockNumber, s.StockCode, sb.BranchNumber, s.BranchCode, sb.InvoiceNumber, sb.PurchasesDate so the output will be: StockCode BranchCode Unit InvoiceNumber PurchasesDate MILO/001 HQ 3 MMC1354 02/03/2004 MILO/001 HQ 6 MMC1360 06/03/2004 Ovatine/002 HQ 10 MMC1450 07/03/2004 Quote George C.K. Low
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.