Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get the quotient alone 1

Status
Not open for further replies.

557

Programmer
Oct 25, 2004
64
US
in oracle trunc( x / 3600 , 0) returns the quotient alone of x when divided by 3600. but since trunc doesn't work in sql server, how do i get the quotient alone when a number is divided by another number
 
Floor(x)

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
donutman,

can you tell me the function in sql server which serves the purpose of lpad of oracle

in oracle, lpad(x , 5 , '0') would return x always as a string of length 5 characters even if it's original length is lesser. 0 will be appended to it's left if it is of shorter lenght
 
There is no system function to do it directly. You must build it.
Code:
[Blue]DECLARE[/Blue] @Test [Blue]AS[/Blue] [Blue]int[/Blue]
[Blue]SET[/Blue] @Test[Gray]=[/Gray]3
[Blue]SELECT[/Blue] [Fuchsia]Right[/Fuchsia][Gray]([/Gray][red]'00000'[/red][Gray]+[/Gray][Fuchsia]Cast[/Fuchsia][Gray]([/Gray]@Test [Blue]AS[/Blue] [Blue]varchar[/Blue][Gray]([/Gray]5[Gray])[/Gray][Gray])[/Gray][Gray],[/Gray]5[Gray])[/Gray]
This is good for non-negative values. You would have to make several changes to get it to work for negatives. What does lpad ( ) do with negatives?
Can anyone explain the odd behavior if you replace varchar with char in the above? You can get it to work but the 2nd 5 has to be a 9!
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top