Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Plese help me

Author  Topic 

boreddy
Posting Yak Master

172 Posts

Posted - 2009-01-22 : 05:21:30
In my table i have nearly 400 records
in this table contain one column length i need to update the column length with range from 900 to 1000 as a random values

thank you in advance

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-01-22 : 05:57:39
Ok, I'm sorry if I misunderstood the question but if you want to create a random number between 900 and 1000 you can use MVJ's function dbo.F_RANDOM_INTEGER found here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69499. To update a table with the values from this function you can do like this:

UPDATE table SET myRandomColumn = dbo.F_RANDOM_INTEGER(900, 1000, NEWID())






- Lumbago
Go to Top of Page

genius_palli
Starting Member

42 Posts

Posted - 2009-01-22 : 06:14:47
Hi everyone..
This is a piece of code in MS-Access, Can anyone please help to write this in SQL.

Sum(IIf([Schedule Status]>=2 And Not IsNull([Contractor ID]),1,0))/Count([Event ID])

Thanks in advance.

Regards
genius_palli
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-22 : 06:23:38
quote:
Originally posted by genius_palli

Hi everyone..
This is a piece of code in MS-Access, Can anyone please help to write this in SQL.

Sum(IIf([Schedule Status]>=2 And Not IsNull([Contractor ID]),1,0))/Count([Event ID])

Thanks in advance.

Regards
genius_palli




May be this

case when ( [Schedule Status]>=2 and coalesce([Contractor ID]),1))/Count([Event ID])is not null ) then
[Schedule Status]+coalesce([Contractor ID]),1))/Count([Event ID]) end
Go to Top of Page

genius_palli
Starting Member

42 Posts

Posted - 2009-01-22 : 06:28:11
thanks raky ..
but i think we need to refine it bit more.. why didnt you used sum function..
Could you please help..

Regards
genius_palli
Go to Top of Page

genius_palli
Starting Member

42 Posts

Posted - 2009-01-22 : 06:35:25
I have even tried to refine it the following way.. but not getting appropriate results..
May i be missing something.. Could you please go through the following piece of code

Sum(case when (([Contractor ID] is not null) and ([Schedule Status]>=2)) then 1 else 0 end)/Count([Event ID]) AS [Percent]

Thanks in advance

Regards
genius_palli
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-22 : 06:38:31
quote:
Originally posted by genius_palli

thanks raky ..
but i think we need to refine it bit more.. why didnt you used sum function..
Could you please help..

Regards
genius_palli




In Sql

SUM FUNCTION takes only one argument but not multiple...

we use Sum function to find sum of values in a column etc
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-22 : 06:43:01
quote:
Originally posted by genius_palli

I have even tried to refine it the following way.. but not getting appropriate results..
May i be missing something.. Could you please go through the following piece of code

Sum(case when (([Contractor ID] is not null) and ([Schedule Status]>=2)) then 1 else 0 end)/Count([Event ID]) AS [Percent]

Thanks in advance

Regards
genius_palli




try this

Sum(
(case when ([Contractor ID] is not null and [Schedule Status]>=2) then 1 else 0 end)/Count([Event ID])) AS [Percent]
Go to Top of Page

genius_palli
Starting Member

42 Posts

Posted - 2009-01-22 : 06:49:40
There u hit the bulls eye..
great.. it worked .. thanks a lot buddy..
Keep in touch.


Regards
genius_palli
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-01-22 : 06:53:01
Ok, next time post your own topic and stop hijacking others. You completely ruined boreddys post now.

- Lumbago
Go to Top of Page

genius_palli
Starting Member

42 Posts

Posted - 2009-01-22 : 06:58:21
Sorry brother.. Ill be careful next time..
I need to execute the query as soon as possible and boreddys topic name also was not appropriate..
Therefore i posted my query there..
I wont repeat the things..


Regards
genius_palli
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-22 : 07:05:41
quote:
Originally posted by genius_palli

There u hit the bulls eye..
great.. it worked .. thanks a lot buddy..
Keep in touch.


Regards
genius_palli




Welcome.....
Go to Top of Page
   

- Advertisement -