Small Sql Statement Brain Teaser

Nov 14, 2003

I’ve just remembered a very small yet challenging SQL statement brain teaser a friend of mine asked me long ago.





Though as simple as it might seem, I still couldn’t figure out how to solve it until this day. I just thought that some of you guys might have an answer to it.





Here is the question:





You have a table named “table1� that has only 2 fields: “name� and “phone�.





This table is populated with the following sample data





NamePhone


---------------------


John111111


Tom222222


Jack333333


John444444


Smith555555


----------------------


5 records








To get all the distinct names in this table, you would write the sql statement:


Select distinct name from table1





And the result would be:





Name


-------


John


Tom


Jack


Smith


-------


4 records





The question is: can you write a sql statement that can return all the distinct names along with their phone numbers.





E.g.





NamePhone


---------------------


John111111


Tom222222


Jack333333


Smith555555


----------------------


4 Records

View 3 Replies


ADVERTISEMENT

Brain Teaser - Stagger The Order Of The Results

Sep 5, 2005

This one has been stumping me for several days. I can run a query thatreturns several different items from several different manufacturers,each with a ranking score. Each manufacturer can have any number ofitems:Item_Name Manufacturer rankItem 1 Manu_A 82Item 2 Manu_A 65Item 3 Manu_A 41Item 4 Manu_B 32Item 5 Manu_C 21Item 6 Manu_B 19However, I would like the records to be ordered so that the highestranking item is shown first, then the next highest item from adifferent manufacturer is shown second, then the next highest item froma third manufacturer is show, etc.:Item 1 Manu_A 82Item 4 Manu_B 32Item 5 Manu_C 21Item 2 Manu_A 65Item 6 Manu_B 19Item 3 Manu_A 41Does anyone have any thoughts on how to order the results in thisfashion?thanks,Matt Weiner

View 2 Replies View Related

Query Brain Teaser - Revenue Projections

Mar 8, 2006

I have a requirement (motivated by a SOX thing) that is just giving mefits. I know it should be easy and I'm probably overthinking it, but Ijust can seem to find the best way to get where I need to go.I have some payment projection data derived from a huge procedure thatI'm dumping into a temp table that looks like looks this:Key Pd Start End AnnualAmt MonthAmt DailyAmt6789 1 2005-06-01 2010-05-31 49,500.00 4,125.00 135.6164386789 2 2010-06-01 2015-05-31 54,450.00 4,537.50 149.1780826789 3 2015-06-01 2020-05-31 59,895.00 4,991.25 164.0958906789 4 2020-06-01 2024-05-31 65,884.50 5,490.38 180.505479(there are actually 6 levels of keys, but you get the idea)I need it to get into a reporting table looking like this:Key Rev Year ProjectedAmt6789 2005 29,021.926789 2006 49,500.006789 2007 49,500.006789 2008 49,500.006789 2009 49,500.006789 2010 20,478.086789 2010 31,924.116789 2011 54,450.006789 2012 54,450.006789 2013 54,450.006789 2014 54,450.006789 2015 22,525.886789 2015 35,117.406789 2016 59,895.006789 2017 59,895.006789 2018 59,895.006789 2019 59,895.006789 2020 24.779.10etc...I'm having a problem wrapping my head around how to get the rows in themiddle of each period.The other, probably minor and statistically insignificant, issue isproration on a leap year. If a proration occurs on a leap year and Ihave to calculate the proration based on a DATEDIFF and an Annual orMonthly Amount, I'm going to be a day over.Anybody have any tricks or ideas???Thanks so much for your help!Jody

View 3 Replies View Related

Stumped...cartesian Product Brain Teaser

May 10, 2007

I have a table with 2 columns as follows:

COORD LEVEL===== =====1 11 22 23 21 32 33 34 35 3


I need to produce a result that has 1 column that is the concatenation of each COORD separated by a '.' by increasing LEVEL


EX: The result should look like this
1.1.1
1.2.1
1.2.2
1.2.3
1.2.4
1.2.5
1.3.1
1.3.2
1.3.3
1.3.4
1.3.5

Please note that the answer must be flexible enough to handle any number of levels and coordinates (although levels will most likely be less than 5 and coordinates less than 100)

Can this be done in a simple SQL statement?

ANY help is very much appreciated.

View 7 Replies View Related

Small Snag With Insert Statement

Jul 7, 2006

I€™m using an access Database with a table called tbltimes. in this table are the following columns:

employeename, employeenum, TimeIn, TimeOut, and PunchDate

Im using an insert statement that looks something like the following to insert a new row each time an employee clocks in.

AccessDataSource1.SelectCommand = "INSERT INTO tbltimes (employeename, employeenum, TimeIn, PunchDate) VALUES ('" & Lblname.Text & "', '" & Lbltemp.Text & "', '" & Lbltime.Text & "', '" & LblDate.Text & "')"

this part of my code is working perfectly.

the part I€™m having trouble with is the next part of my code where i would search the rows in tbltimes and find the row WHERE employeename = Lblname.text & TimeIn is not null & TimeOut IS null. Then INSERT Lbltime into the Timeout column of that existing row.

Any ideas as to the easiest way to accomplish this would be a great help, I€™m officially stumped atm.

View 5 Replies View Related

How To I Enter A Small Square Or A Small Circle In A NVARCHAR Field?

Dec 25, 2006

I want to store a small cirle in a text field. Can anyone tell me how I can enter it in ascii code.

Thanks

View 4 Replies View Related

SQL Teaser

May 31, 1999

I have a table (POS) with 3 columns and 4 rows:

KEY COLUMNA COLUMNB
1 1 dog
2 1 cat
3 2 dog
4 2 cat

What is the SQL to return
COLUMNA COLUMNB
1 dog
2 dog
?

Thanks

View 2 Replies View Related

SQL Brain Fart

Oct 5, 2004

I feel like I am having a total brain fart. I am trying to use a select * where statement to get all the records from my database that match a given setup and using a URL variable:
Code:

SELECT * FROM dbo.TerraLogMain WHERE Volume = '#URL.VolumeID#'


Now I know for a fact that there are multiple records for Volume = Maps6 (for example) but I am only getting one record returned.

It also looks like the URL variable is getting passed okay:
Code:

http://localhost/GISTerraLog/VolumeDetail.cfm?VolumeID=Maps6

I also tried using a direct statement just to see if that gave up any hints:

SELECT *
FROM dbo.TerraLogMain
WHERE Volume = 'Maps6'

but I still only get one record returned.

So any clues as to what I am missing?

Thanks for any help!

Cheers,
Melissa

View 8 Replies View Related

Having A MAJOR Brain Fart Here...

Feb 18, 2007

Guys I'm sorry to be asking such a routine question...
I'm having trouble figuring out how to make this function dynamic enough to handle multiple insert statements.1 public int Add()
2
3 {
4
5 string SQL;
6
7 SQL = "INSERT INTO [BuildingInterior] (PropertyID, CeilingHeight, " +
8
9 "LoadingDocks, PassengerElevators, FreightElevators, PassengerEscalators, " +
10
11 "FireSprinklersID, SecurityCameras, SmokeDetection, FireAlarms, " +
12
13 "GasDetection, SecureAccess, HeatTypeID, AirConditioningID, " +
14
15 "AirExchange, InternetAccessID, InteriorDescription) " +
16
17 "VALUES ( @PropertyID, @CeilingHeight, " +
18
19 "@LoadingDocks, @PassengerElevators, @FreightElevators, @PassengerEscalators, " +
20
21 "@FireSprinklersID, @SecurityCameras, @SmokeDetection, @FireAlarms, " +
22
23 "@GasDetection, @SecureAccess, @HeatTypeID, @AirConditioningID, " +
24
25 "@AirExchange, @InternetAccessID, @InteriorDescription)";
26
27 PropertyDB myConnection = new PropertyDB();
28
29 SqlConnection conn = myConnection.GetOpenConnection();
30
31 SqlCommand cmd = new SqlCommand(SQL, conn);
32
33 cmd.Parameters.Add("@PropertyID", SqlDbType.Int).Value = PropertyID;
34
35 cmd.Parameters.Add("@CeilingHeight", SqlDbType.NVarChar, 50).Value = CeilingHeight;
36
37 cmd.Parameters.Add("@LoadingDocks", SqlDbType.NVarChar, 50).Value = LoadingDocks;
38
39 cmd.Parameters.Add("@PassengerElevators", SqlDbType.NVarChar, 50).Value = PassengerElevators;
40
41 cmd.Parameters.Add("@FreightElevators", SqlDbType.NVarChar, 50).Value = FreightElevators;
42
43 cmd.Parameters.Add("@PassengerEscalators", SqlDbType.NVarChar, 50).Value = PassengerEscalators;
44
45 cmd.Parameters.Add("@FireSprinklersID", SqlDbType.Int).Value = FireSprinklersID;
46
47 cmd.Parameters.Add("@SecurityCameras", SqlDbType.NVarChar, 50).Value = SecurityCameras;
48
49 cmd.Parameters.Add("@SecurityAlarms", SqlDbType.NVarChar, 50).Value = SecurityAlarms;
50
51 cmd.Parameters.Add("@SmokeDetection", SqlDbType.NVarChar, 50).Value = SmokeDetection;
52
53 cmd.Parameters.Add("@FireAlarms", SqlDbType.NVarChar, 50).Value = FireAlarms;
54
55 cmd.Parameters.Add("@GasDetection", SqlDbType.NVarChar, 50).Value = GasDetection;
56
57 cmd.Parameters.Add("@SecureAccess", SqlDbType.NVarChar, 50).Value = SecureAccess;
58
59 cmd.Parameters.Add("@HeatTypeID", SqlDbType.Int).Value = HeatTypeID;
60
61 cmd.Parameters.Add("@AirConditioningID", SqlDbType.Int).Value = AirConditioningID;
62
63 cmd.Parameters.Add("@AirExchange", SqlDbType.NVarChar, 50).Value = AirExchange;
64
65 cmd.Parameters.Add("@InternetAccessID", SqlDbType.Int).Value = InternetAccessID;
66
67 cmd.Parameters.Add("@InteriorDescription", SqlDbType.NVarChar, 50).Value = InteriorDescription;
68
69 cmd.ExecuteNonQuery();
70
71 cmd.CommandText = "SELECT @@IDENTITY";
72
73 this.BuildingInteriorID = Int32.Parse(cmd.ExecuteScalar().ToString());
74
75 conn.Close();
76
77 return this.BuildingInteriorID;
78
79 }
80

 Should I just pass an array of column names and use the AddWithValues SqlCommand method while looping through the array?
Any comments are greatly welcomed.

View 2 Replies View Related

Localization.Brain Storming.

Mar 16, 2007

 Hello,I am working on a Blog and a Documents systems.What I need is:1. Each blog can have various language versions.2. Each document can have various language versions.I have been thinking about this and I end up with two approaches:1. Use a structure where all tables depend on a localized table:BLOGS|---- BlogsLocalized|---- BlogsPosts|---- BlogsRatings|---- BlogsComments2. Use a structure where each table has a localized versionBLOGS|---- BlogsLocalized|---- BlogsPosts|---- BlogsPostsLocalized|---- BlogsComments|---- BlogsCommentsLocalized3. Create a simpler, without localization, in SQL and in my web sites have different versions for each language.The same approach is under thinking for DocumentsTables.Could someone give me some advice?I have been looking in internet but until no I couldn't find anything really useful.Thanks,Miguel

View 1 Replies View Related

Brain-Dead Newbie - SQL Question

Sep 8, 2005

Any help is sincerely appreciated:I have data in a table that represents the following:Admin Visit Type            Registration Date         Discharge Date D                                    20050301                  20050301D                                    20050301                  20050301W                                   20050301                  20050301E                                    20050301                  20050301D                                    20050301                  20050302W                                   20050301                 20050303W                                   20050301                 20050311D                                    20050301                 20050301Patient Type is always and I for the records I want but there are also Patient Types = O which I don't care about..What I would like to do is accoumlate a counter on the number of Registrations per date as well as Discharges per date.There can be thousands of registrations per day as well as thousands of discharges per day.  So lets say I want to pass a date parameter to accumulate the total registrations and discharges per day.  I have beat my head against the desk for the last two days because I believe this is a simple query but I just cannot get the results I want  - so any help is greatly appreciated.   I have written the following sql but I do not get a sum of the total registrations and discharges and EXPR3 and Expr4 always equal each other which is not the case .  For example on 20040301 I have 88 registrations and 17 discharges but I can't ever get the correct totals...I wrote the following in Query Analyzer - but it does not work and I have went around in circles and have tried so many things I am just frustrated.........Declare @Parm_Beg_Date as nvarchar(8)Set @Parm_Beg_Date = 20040313
SELECT
Patient_Visit_Result_Master.PVR_Admin_Visit_Type,Patient_Visit_Result_Master.PVR_Patient_Type, Patient_Visit_Result_Master.PVR_Registration_Date,Patient_Visit_Result_Master.PVR_Discharge_Date, Count(Distinct(Patient_Visit_Result_Master.PVR_Registration_Date)) as Expr3,Count(Distinct(Patient_Visit_Result_Master.PVR_Discharge_Date)) as Expr4
FROM         Patient_Visit_Result_Master INNER JOINPatient_Visit_Result_Master Patient_Visit_Result_Master_1 ON Patient_Visit_Result_Master.PVR_Hospital_ID = Patient_Visit_Result_Master_1.PVR_Hospital_ID  AND @Parm_Beg_Date = Cast(Patient_Visit_Result_Master_1.PVR_Registration_Date as nvarchar(8))or@Parm_Beg_Date = Cast(Patient_Visit_Result_Master_1.PVR_Discharge_Date as nvarchar(8))
WHERE     (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'E') AND (Patient_Visit_Result_Master.PVR_Patient_Type =  'I')  AND (Cast(Patient_Visit_Result_Master.PVR_Registration_Date as nvarchar(8)) = @Parm_Beg_Date)  OR    (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'D') AND (Patient_Visit_Result_Master.PVR_Patient_Type =  'I')  AND (Cast(Patient_Visit_Result_Master.PVR_Registration_Date as nvarchar(8)) = @Parm_Beg_Date)
 Or (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'W') AND (Patient_Visit_Result_Master.PVR_Patient_Type =  'I') and (Cast(Patient_Visit_Result_Master.PVR_Discharge_Date as nvarchar(8)) = @Parm_Beg_Date)
 Or (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'D') AND (Patient_Visit_Result_Master.PVR_Patient_Type =  'I') and (Cast(Patient_Visit_Result_Master.PVR_Discharge_Date as nvarchar(8)) = @Parm_Beg_Date)
GROUP BY Patient_Visit_Result_Master.PVR_Admin_Visit_Type,Patient_Visit_Result_Master.PVR_Patient_Type, Patient_Visit_Result_Master.PVR_Registration_Date,Patient_Visit_Result_Master.PVR_Discharge_Date
Order By Patient_Visit_Result_Master.PVR_Admin_Visit_TypeThanks in advance

View 10 Replies View Related

Nasty Mirroring Split Brain Situation

Mar 27, 2007

Yesterday I had a nasty mirroring problem.



The principal and the mirror server are both running SQL Server 2005 64-bit Enterprise Edition. Witness is running Workgroup Edition. We are running in high availability mode (SAFETY ON).



3 nights before something strange happened and 1 database failed over (out of the six being mirrored) for some unknown reason. The other 5 didn't. We failed that one back and all seemed ok over the weekend.
We came in Monday and found that the main live OLTP database was showing as the Principal on BOTH servers (in SMO/Management Studio and also in sys.database_mirroring). This is the "split brain" scenario that the presence of the witness is supposed to prevent. Both databases were accessible with a USE statement - clearly not right.



I pondered what to do, eventually I decided to remove mirroring from this database. That was ok until suddenly a few minutes later we realised the (original) Principal was in recovery! uisers of course were kicked out/unable to connect. I tried to force recovery with RESTORE DATABASE dbname WITH RECOVERY but it complained users were connected!



I had to KILL the users then recovery proceeded and the database became available again. I forced the mirror offline to prevent accidental usage.



This is obviously a nasty situation where mirroriing - which is supposed to prevent downtime - actually caused it instead.



I intend to log a call with CSS but I wanted to warn other users if they encounter something similar - it has shaken my confidence in mirroring quite severely.

View 4 Replies View Related

Count Up Based On Unique Value -- Brain Freeze

Apr 17, 2008



Ok... I know this is something that I've seen and probably done before....

I have a value that will show up multiple times in a table. I want to order the table by that value and then count up from 1 to however many items that it shows up as.

The example below shows the results I want. Value1 and Value2 are in the table, LineNumber is what I need to generate.








Value1
Value2
LineNumber

1
Hey
1

1
Can
2

1
Someone
3

1
Help
4

1
With
5

1
This
6

2
Very
1

2
Simple
2

2
Issue
3

2
As
4

2
I
5

3
Have
1

3
A
2

3
Brain
3

3
Freeze
4



--Thanks--

View 4 Replies View Related

I Need Help With Cleaning A Phone Number Column, Brain Freeze

Feb 26, 2002

For anyone who can help me resolve this minor data issue. I am trying to clean a phone number column so that all numbers are reflected in the same way. I have phone numbers in my column in this this format:

(123)123-1234
123-123-1234
(123) 123-1234

How can I clean this column so that the numbers are reflected in this way: 1231231234

I'm having brain freez right now. Help me please!!! Thanks in Advance

View 2 Replies View Related

A Small Problem

Aug 6, 2005

How to retreive the value of last identity has been updated in a database (SQL Server)?

View 1 Replies View Related

Small Doubt

May 29, 2008

in command promt how to come out c drive to d drive

View 2 Replies View Related

I Need Sql Small Query

Mar 10, 2007

in my table have two column one post(varchar) and another one views(decimal).in table have no.of data's.......
sample data's

Ex i want this Result
post views post views

std 400 std 400
abc 100 abc 100
dbn 10 sdfe 75
sdfe 75 dbn 10
.... .....
..... ....
....


i need one query....... condition view best top 10 post based on views column

View 2 Replies View Related

Small Query

Sep 12, 2007

Hi,

I need to display only the char having start with 'ACCT -AMOUNT',Now problem is that some records having the lower case character like 'acct amount'.
But i want to display only the upper case char start with 'ACCT-AMOUNT'.

I have to used the 'like ' statement but it is showing all the row inculding the lower case also.

Please give me some clue reg. the issues.

Thanks,BPG

View 3 Replies View Related

A Small SQL Puzzle

Sep 26, 2007

Hi,Probable there is a simple solution for this, hopefully someone candirect me in the right direction.I have a table with a persons firstname, lastname, birthdate andaddress. However, I want to select only one person per address, namelythe eldest of all persons living on the same address.Can anyone provide me a solution?Thanks in advance.Duncan

View 2 Replies View Related

Small Problem

Jul 20, 2005

HelloI have a case where Partners are some kind of Super-Users and arestored in a SQL Server database. Best is IMO to put both in the sametable:table Customers:CustomerID[pr.key][blabla]PartnerIDBut of course I have to reference the partnerid from another table andI want SQL Server to maintain the integrity rules. I could splitCustomers en Partners into different tables, but that would not bewise i think.Or I could just reference the CustomerID from the other table and-know- that we are talking about a partner, but in that case it itpossible to reference a customer that is not a partner, and i want toavoid that.Any ideas?Freek Versteijn

View 4 Replies View Related

Small List Of How Do I's

Nov 27, 2007

Consider a recordset consisting of
Vendor, Invoice, InvAmt, Item,ItemAmt
1, 'A12345', 100.00,'Item1', 25.00
1, 'A12345', 100.00,'Item2', 50.00
1, 'Z22222', 200.00,'Item1',100.00

1, 'Z22222', 200.00,'Item3', 50.00
2, 'A12345', 300.00,'Item4,' 250.00

I have a report that groups by vendor and then by invoice within a vendor.

I want to create a report totals that contains

Number of vendors=2
Number of invoices=3
Total Inv Amounts=600.00
Total Item Amounts=475.00


How?
Number of vendors is =count(distinct vendors) ??
Cant do that for # Invoices because of possible duplicate invoices used by different vendors.
How do i get the total invamt? Each occurrence of the invamt fld is in a list2 as =first(invamt).
I really need the sum of each first(invamt).

Thanx Up Front.
Jerry C

View 9 Replies View Related

Small Prob

Aug 17, 2007

i need to concatenate this two database fildes

PATNT_REFNO_NHS_IDENTIFIER defined as varchar
PATNT_REFNO defined as numeric

out put of these tewo colomns like

PATNT_REFNO_NHS_IDENTIFIER = NPA0123
PATNT_REFNO = 0125487


so i need to get a result like
NPA01230125487

any idea

regards
Niranga

View 1 Replies View Related

Small Version?

Jun 18, 2007

I currently use JET 4.0 as my database in a small app I distribute. SQL Server Express is way way too big to distribute. I am looking to move to a better database.

Is there a version of SQL that gives simple database CRUD support, but is super small to distribute? I am also considering Firebird as it's a full database and only 3MB on the client as an embedded tool.

Ian

View 1 Replies View Related

Small Question

May 22, 2006

i have table cosists of 3 columns
i need to select multiple rows from the table
example : i need to select rows with id=(1,5,9,7,11,15,20,23,42,65) in one select statement
can any body answer me?
and i will give him a( )

View 3 Replies View Related

SQL Or Access For A Small Forum

Jan 18, 2004

Hi,

I'm just about to launch a forum, and right now its built in ASP classic with an Access db. I origianlly used Access because most hosts charge extra for MS-SQL server. Recently I switched to Jodohost who offers Access, MS-SQL and MySql for at no additional cost. So now that I have the option, I would like to pick the best solution before I launch.


* My questions are...

- What is the best db solution to go with for a currently small forum?

- How problematic do you think a data migration would be in the future if I stayed with Access for now and upgraded to MS-SQL with a full forum?

- Is it just smarter to go with MS-SQL now, with an empty forum, regardless of any preformance issues because potential migration problems are a greater risk?

- At what point does the speed of MS-SQL at high volumes over come the potential lags in accessing MS-SQL if it is hosted on a different machine from the one hosting the webpages?



* And please keep in mind...

- I have no db training. I can muddle through Access well enough, but administrating MS-SQL I think might be another story

- This fourm will start off very small, but could grow to be quite large

- I may not stay with jodohost, and would therefore likely have to pay more for MS-SQL (which I woudl rather not do)

View 1 Replies View Related

Please Help With Small Table Design

Mar 10, 2004

Hello, could someone pls help me with this table design.

I have a project table and a code table. The code table has things like priorities (High, Medium, Low).

Now, I want all projects to be able to use these 'global' codes as well as define their own. So, they could define their own priority code 'Critical', that only their project can see.

Any help would be great.

View 1 Replies View Related

Please Help With This View - Small Modification

Nov 17, 2005

I have listed a view below and a portion of the result set that is returned when I run the code in Query Analyzer.  This is part of a timesheet application that logs hours per SCHLSTUID per SECTIONID per week.  This returns the SCHLSTUID(user's ID), SECTIONID, Date that the week starts, the first date that time was logged.  The user could be in several SECTIONID's for the same week.  I need to modify this so that it returns the date that the first time was logged for any of the SECTIONID's per week.  I know that this is probably something simple that I'm overlooking but I just can't get it to work correctly.Example:  SCHLSTUID   SECTIONID   ATTSTARTDT                     FirstTimeEnteredDOn601868445      EN4AR001      2005-09-18 20:59:21.120    2005-09-19 20:59:21.120601868445      MAA1R001      2005-09-18 20:59:21.120    2005-09-18 20:59:21.120This would need to return 2005-09-18 20:59:21.120------------------------------------------------------------------------------------------------------601868445      EN4AR001      2005-10-02 20:59:37.427    2005-10-02 20:59:37.427601868445      MAA1R001      2005-10-02 20:59:37.427    2005-10-02 20:59:37.427This would need to return either 2005-10-02 20:59:37.427------------------------------------------------------------------------------------------------------601868445      EN4AR001      2005-10-09 20:59:37.823    2005-10-09 20:59:37.823601868445      MAA1R001      2005-10-09 20:59:37.823    2005-10-13 20:59:37.823This would need to return 2005-10-09 20:59:37.823----------------------------------------------------------------------------------------------------------------------------------------------------CREATE VIEW dbo.vExportStartWeekASSELECT     TOP 100 PERCENT schlstuid, sectionid, ATTSTARTDT, MIN(TimesheetDate) AS FirstTimeEnteredOnFROM         (SELECT     schlstuid, sectionid, ATTSTARTDT, ATTSTARTDT AS TimesheetDate, sunmns AS TimeEntered                       FROM          TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, ATTSTARTDT AS TimesheetDate, sunhrs AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 1, ATTSTARTDT) AS TimesheetDate, monmns AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 1, ATTSTARTDT) AS TimesheetDate, monhrs AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 2, ATTSTARTDT) AS TimesheetDate, tuemns AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 2, ATTSTARTDT) AS TimesheetDate, tuehrs AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 3, ATTSTARTDT) AS TimesheetDate, wedmns AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 3, ATTSTARTDT) AS TimesheetDate, wedhrs AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 4, ATTSTARTDT) AS TimesheetDate, Thrmns AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 4, ATTSTARTDT) AS TimesheetDate, Thrhrs AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 5, ATTSTARTDT) AS TimesheetDate, Frimns AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 5, ATTSTARTDT) AS TimesheetDate, Frihrs AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 6, ATTSTARTDT) AS TimesheetDate, Satmns AS TimeEntered                       FROM         TimeSheetDailyAttendance                       UNION ALL                       SELECT     schlstuid, sectionid, ATTSTARTDT, DATEADD(d, 6, ATTSTARTDT) AS TimesheetDate, Sathrs AS TimeEntered                       FROM         TimeSheetDailyAttendance) TimesheetDatesWHERE     (TimeEntered <> 0)GROUP BY schlstuid, sectionid, ATTSTARTDTORDER BY schlstuid----------------------------------------------------------------------------------------------------------------------------------------------------This is a portion of what is returned:SCHLSTUID   SECTIONID   ATTSTARTDT                     FirstTimeEnteredDOn601868445      EN4AR001      2005-09-18 20:59:21.120    2005-09-19 20:59:21.120601868445      MAA1R001      2005-09-18 20:59:21.120    2005-09-18 20:59:21.120601868445      EN4AR001      2005-09-25 20:59:36.670    2005-09-25 20:59:36.670601868445      EN4AR001      2005-10-02 20:59:37.427    2005-10-02 20:59:37.427601868445      MAA1R001      2005-10-02 20:59:37.427    2005-10-02 20:59:37.427601868445      EN4AR001      2005-10-09 20:59:37.823    2005-10-09 20:59:37.823601868445      MAA1R001      2005-10-09 20:59:37.823    2005-10-13 20:59:37.823----------------------------------------------------------------------------------------------------------------------------------------------------Thank you for any help that you can give me.Scott

View 3 Replies View Related

Sql Small Date Time

Dec 27, 2001

when i insert an empty date from an asp page, sql 7.0 generates a default value 1/1/1900. This is normal. However, I need to know how do I turn that feature off so I would not generate the default value.

Currently, my front in application uses asp--vb scripts. Please help.

I tried assigning a null value to my variant, but sql still generate that default date/time

View 1 Replies View Related

Small Permissions Question

Mar 12, 2001

Hello,
I'd like to confirm something regarding SQL Server account permissions. Is the NT domain admin also a member of the sysadmin role on the local server running SQL Server 7.0 on an NT 4.0 platform?
Thank you

View 2 Replies View Related

Timing Out On Small Update

Jan 24, 2001

I am trying to run a program that works on another site but with a copy of the database(SQL6.5) and the vb front end I keep getting a timeout error.

The vb bit is trying to run an update statement on a table with just over 2000 rows. I cannot amend the vb side because this is an .exe

Is there something I might not have done on the server that could be causing this not to work, i.e configuration issues, bigger logs


Please help!!

View 2 Replies View Related

Massive TRN File, But Small DB

Apr 5, 2006

Hi Everyone,

We have a large and active MSSQL 2000 database. Recently, after a rebuild of the server, we had a problem with the SQL service SQLSERVERAGENT. The service could not start as the service account lost local permission to the registry. During this time, all of the data being sent to the database from our application accumulated into the database .ldf file. By the time we were able to get the service restarted, our .ldf file was approx. 28 Gigs. When the service restarded, the .ldf file shrunk down to regular size,about 40 megs, and the .trx tlog file grew up to 28 gigs for that specific period (new file every hour).

The problem is, the database file (database.mdf) stayed about the same as it was before the service was restarted. When the .ldf transfered to the .trn none of the 28 gigs of data got stored in the database. What does this mean? Perhaps with the service stopped the application using the db saw problems and did not commit the data making it all useless? Or is it possible that the data in the .trn log just needs to be forced to commit to the .mdf???

Is there any way to verify the data in the 28 gig .trn file and figure out if we should get it stored to the database? If yes, how would we go about verifying it, and after that how would we force it to commit to the .mdf file? Am I on the right track here or is it not as I see it??

Thanks!
Mike

View 4 Replies View Related

Small Problem On Replication

May 7, 1999

i have performed all the steps for the replication there are two problems i encounytring
(i) how to check whether the replication is working or not
(ii) can replication on the subscribing server automatically create the table which publishing server is publshing
(iii)please tell me someother forums for sql server
waiting for reply
ashish bhatnagar

View 2 Replies View Related

A Small Query Problem

Feb 15, 2008

Hello All,
I have a database and I am trying to run a query against it, it returns the data fine, I just want it displayed differently. Here is the example; I am a novice at SQL I dabble here and there so any help would be great!

Base Code
Select LOA.Account0 as 'Account Name'
From local_accounts LOA
Where LOA.Account0 like '%Microsoft%'
Group by LOA.ACCOUNT0


Account Name
Win32_UserAccount.Domain='Microsoft',Name='Jason'


I would like the data to be displayed differently in my query. I would like just the domain user name to appear in the row.

Account Name
MicrosoftJason

Does anyone have example code of something like this.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved