Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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..

George C.K. Low

  • Administrators
Posted
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.)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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?

George C.K. Low

  • *Experts*
Posted

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

"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
Posted

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

George C.K. Low

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...