Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Thursday, March 22, 2012

DISTINCT Conflicting with my query

I need p.phonenumber in there but then it messes up my DISTINCT ON m.number because I end up with dup m.numbers if I run just the inner select statement during testing.
But then I need the phonenumber in that subquery so that I can do list.phonenumber
ahh!

UPDATE Master

SET master.homephone = list.phonenumber

FROM MASTER m

INNER JOIN

(SELECT DISTINCT p.number, topphone.phonenumber

FROM phones p

INNER JOIN (SELECT top 1 phonenumber from phones) as topphone ON topphone.number = p.number

WHERE p.phonetypeID = 1

AND ISNULL(p.good, 0) <> 0

AND LEN(p.phonenumber) = 10

) AS list ON m.Number = list.Number

WHERE m.homephone IS NULL OR m.homephone = ''


Error:
Msg 156, Level 15, State 1, Procedure Skiaa, Line 66
Incorrect syntax near the keyword 'top'.
Msg 156, Level 15, State 1, Procedure Skiaa, Line 88
Incorrect syntax near the keyword 'top'.
I want to update m.homephone with the p.phonenumber based in the filtering critiria I have specified but this simple task is turning out to be a pain.

Without actually trying to recreate the tables on my local server, I'll try to answer this. This is assuming it's actually something wrong with evaluating the top function within your derived table structure.

Anyway, try something like this instead...

UPDATE Master

SET master.homephone = list.phonenumber

FROM MASTER m

INNER JOIN

(SELECT DISTINCT p.number, topphone.phonenumber

FROM phones p

WHEREp.phonetypeID = 1

AND ISNULL(p.good, 0) <> 0

AND LEN(p.phonenumber) = 10

AND p.number = (SELECT TOP 1 phonenumber from phones)

) AS list ON m.Number = list.Number

WHERE m.homephone IS NULL OR m.homephone = ''

OR...

DECLARE @.max_phone NVARCHAR(100)
SET @.max_phone = (SELECT TOP 1 phonenumber from phones)

UPDATE Master

SET master.homephone = list.phonenumber

FROM MASTER m

INNER JOIN

(SELECT DISTINCT p.number, topphone.phonenumber

FROM phones p

WHEREp.phonetypeID = 1

AND ISNULL(p.good, 0) <> 0

AND LEN(p.phonenumber) = 10

AND p.number = @.max_phone) AS list ON m.Number = list.Number

WHERE m.homephone IS NULL OR m.homephone = ''

Monday, March 19, 2012

Displaying Report in Multicolor

In a table i'm having numbers from 1 to 10 , in crystal i want to show no. 1 to 5 in different color and from 5 to 6 in different color . Cna i do this in Segate Crystal Report ?? Pls help me...You can do a Conditional Format. You enter a formula to determine what color the field should be.

For example, in CR 8.5 using RDC... Right-click on the field you want colored, click Format, on the Border Tab, click the 'x-2' button and type in your formula (ex. {Field1} = 5), choose the color from the dropdown menu... Maybe you could use a Case Statement to select multiple colors?

Sunday, March 11, 2012

Displaying Remainders

I need to show the whole number and remainder each as wole numbers. I have been trying to use modulo on the advice from a friend, but I don't understand this function.

More of an exlpanition: I am working with inventory and shipping quantities. If a pallet consists of 9 cases, and I have an order for 20 cases, I need to display in a report 2 pallets and 2 cases. These numbers can be in the same column or different columns...at this point I just need to be able to display the numbers.

Is there any way to do this? Any help would be appreciated.

-Thanks

P.S.

I posted this in the general forums before I realized I was there...not sure how to move posts, so I double-posted....sorry.

Hello,

Try this:

=cStr(cInt(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value)) + " Pallets " + cStr(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value) + " Cases"

Hope this helps.

Jarret

|||

This is what I need. Thanks

On this solution, how do I force a round down on the "Pallet" number (18.66667 is showing as 19 but needs to show as 18)?

I tried this:

=cStr(Floor(cInt(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value))) + " Pallets " + cStr(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value) + " Cases"

But this didn't change anything.

What are your thoughts?

-EDIT-

I used the cInt to remove the decimals

=cStr(Floor(cInt(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value))) + " Pallets " + cStr(cInt(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value)) + " Cases

|||

Try this:

=cStr(Floor(Fields!CasesOrdered.Value / Fields!CasesOnPallet.Value)) + " Pallets " + cStr(cInt(Fields!CasesOrdered.Value Mod Fields!CasesOnPallet.Value)) + " Cases

I should have used the Floor function on the Pallets calculation (instead of cInt). Then, the cInt on the Cases will remove the decimals.

Hope this helps.

Jarret

|||Perfect! Everything works exactly like is should now. Thanks for your henp.

Displaying numbers like 05 instead of 5

Hi,
In my database I have a table with two digit integers.
When I make a query, I would like see something like this
01
02
03
04
05
06
...
10
11
12
instead of
1
2
3
4
5
6
...
10
11
12
Is there a function for doing that?
Thanks!declare @.i int
set @.i = 3
select @.i, right('00' + convert(varchar(4),@.i),2)
-- --
3 03
Roy Harvey
Beacon Falls, CT
On Mon, 03 Jul 2006 12:35:49 -0400, LEM <anonymous@.nospam.com> wrote:

>Hi,
>In my database I have a table with two digit integers.
>When I make a query, I would like see something like this
>01
>02
>03
>04
>05
>06
>...
>10
>11
>12
>
>instead of
>1
>2
>3
>4
>5
>6
>...
>10
>11
>12
>Is there a function for doing that?
>Thanks!|||Thanks Roy!|||select right( '00' + convert(varchar(2),ColumnName),2)
example
declare @.i int
select @.i =9
select right( '00' + convert(varchar(2),@.i),2)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
LEM wrote:
> Hi,
> In my database I have a table with two digit integers.
> When I make a query, I would like see something like this
> 01
> 02
> 03
> 04
> 05
> 06
> ...
> 10
> 11
> 12
>
> instead of
> 1
> 2
> 3
> 4
> 5
> 6
> ...
> 10
> 11
> 12
> Is there a function for doing that?
> Thanks!|||Okay so I was fashionably late since Roy Harvey already gave the answer
(even used the same variable name)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
SQL Menace wrote:
> select right( '00' + convert(varchar(2),ColumnName),2)
> example
> declare @.i int
> select @.i =9
> select right( '00' + convert(varchar(2),@.i),2)
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
>
> LEM wrote:

Friday, February 17, 2012

display numbers in a specific format

how can i display numbers in a specific format
like function: format(Num,"#,###") in msaccess?
thanksYour client application controls how numbers are displayed. SQL Server
has no control over that so you need to refer to whatever client /
presentation app you are using (you didn't specify).
The only way to do that from SQL would be to return the number as a
string (not really a good idea). Lookup CONVERT in Books Online if you
want to know how to do that.
David Portas
SQL Server MVP
--|||There is no such format in SQL Server. As David says, this is usually
controlled by the client application and/or the regional settings or
preferences of the end user.
If you really feel strongly enough that SQL Server should do this for you
(you may have compelling reasons), then you can use CONVERT() or STR().
Both are documented in Books Online.
"Sam" <focus10@.zahav.net.il> wrote in message
news:eHv7pvH4FHA.1416@.TK2MSFTNGP09.phx.gbl...
> how can i display numbers in a specific format
> like function: format(Num,"#,###") in msaccess?
> thanks
>
>