473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

select query question

n8kindt
221 100+
i have a bunch of blank values in my query. my data looks like this


z z z z s _ _ _ _ _ _
z z z s _ _ _ _ _ _ _
z z z z z z z z z s _
z s _ _ _ _ _ _ _ _ _
z z z z z s _ _ _ _ _

z = data stored in field
s = last field with data (reading left to right) stored in the row
_ = blank (null) fields

i want my query to automatically copy the last field (y) into all the blank (_) fields.
so it will like like this:

z z z z s s s s s s s
z z z s s s s s s s s
z z z z z z z z z s s
z s s s s s s s s s s
z z z z z s s s s s s


how can i accomplish this?

this would also be acceptable:

z z z z s _ _ _ _ _ s
z z z s _ _ _ _ _ _ s
z z z z z z z z z s s
z s _ _ _ _ _ _ _ _ s
z z z z z s _ _ _ _ s

thanks in advance for your time.
Mar 20 '08 #1
3 1374
PianoMan64
374 Expert 256MB
have a bunch of blank values in my query. my data looks like this


z z z z s _ _ _ _ _ _
z z z s _ _ _ _ _ _ _
z z z z z z z z z s _
z s _ _ _ _ _ _ _ _ _
z z z z z s _ _ _ _ _

z = data stored in field
s = last field with data (reading left to right) stored in the row
_ = blank (null) fields

i want my query to automatically copy the last field (y) into all the blank (_) fields.
so it will like like this:

z z z z s s s s s s s
z z z s s s s s s s s
z z z z z z z z z s s
z s s s s s s s s s s
z z z z z s s s s s s


how can i accomplish this?

this would also be acceptable:

z z z z s _ _ _ _ _ s
z z z s _ _ _ _ _ _ s
z z z z z z z z z s s
z s _ _ _ _ _ _ _ _ s
z z z z z s _ _ _ _ s

thanks in advance for your time.
Let Assume for the moment since I don't have field names that we're going to call each column by the name of Col and the rows as records.

The way that you'd need to write the query is to do the following:

SELECT LastValue(Col1,nz(Col2,0),nz(Col3,0),nz(Col4,0),nz (Col5,0),nz(Col6,0),nz(Col7,0),nz(Col8,0),nz(Col9, 0),nz(Col10,0) as Col11 FROM {TableName}

Create a query with the following SELECT Statement.

Notice that I've created a function called LastValue(). You would need to put in the parathasise () the column names for each one of them.

Copy and Paste the following into a module

Open the Visual Basic Code Editor ALT-F11

Select Insert -> Module

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function LastValue(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10)
  3.  
  4.     If Col10 <> 0 then
  5.            LastValue = Col10
  6.            Exit Function
  7.    End if
  8.    If Col9 <> 0 Then
  9.            LastValue = Col9
  10.            Exit Function
  11.    End if
  12.    ' Continue with the conditional statements until you have all columns defined
  13.    If Col# <> 0 then
  14.           LastValue = Col#
  15.           Exit Function
  16.    End if
  17.  
  18. End function
  19.  
Mar 20 '08 #2
n8kindt
221 100+
Let Assume for the moment since I don't have field names that we're going to call each column by the name of Col and the rows as records.

The way that you'd need to write the query is to do the following:

SELECT LastValue(Col1,nz(Col2,0),nz(Col3,0),nz(Col4,0),nz (Col5,0),nz(Col6,0),nz(Col7,0),nz(Col8,0),nz(Col9, 0),nz(Col10,0) as Col11 FROM {TableName}

Create a query with the following SELECT Statement.

Notice that I've created a function called LastValue(). You would need to put in the parathasise () the column names for each one of them.

Copy and Paste the following into a module

Open the Visual Basic Code Editor ALT-F11

Select Insert -> Module

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function LastValue(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10)
  3.  
  4.     If Col10 <> 0 then
  5.            LastValue = Col10
  6.            Exit Function
  7.    End if
  8.    If Col9 <> 0 Then
  9.            LastValue = Col9
  10.            Exit Function
  11.    End if
  12.    ' Continue with the conditional statements until you have all columns defined
  13.    If Col# <> 0 then
  14.           LastValue = Col#
  15.           Exit Function
  16.    End if
  17.  
  18. End function
  19.  
this is exactly what i need. thanks so much. wow, i can't be thankful enough for the help i get from this site. it is truly outstanding!!

cheers,
nate
Mar 20 '08 #3
n8kindt
221 100+
this is exactly what i need. thanks so much. wow, i can't be thankful enough for the help i get from this site. it is truly outstanding!!

cheers,
nate
everything works great. however, after viewing the query in datasheet mode and then pulling it back into design, there is some serious lagging. it flickers in and out of being responsive anywhere from 5-100 (not even kidding) times.

it only happens when my function is used in the query. here's my code:

SQL
Expand|Select|Wrap|Line Numbers
  1. SELECT [0].ID, [1].ID, [2].ID, [3].ID, [4].ID, [5].ID, [6].ID, [7].ID, [8].ID, [9].ID, [10].ID, [11].ID, ColumnEnd([0.ID],nz([1.ID],0),nz([2.ID],0),nz([3.ID],0),nz([4.ID],0),nz([5.ID],0),nz([6.ID],0),nz([7.ID],0),nz([8.ID],0),nz([9.ID],0),nz([10.ID],0),nz([11.ID],0)) AS StoredFC
  2. FROM (((Table1Info AS 2 RIGHT JOIN Table1Info AS 1 ON [2].[Recruited By] = [1].ID) RIGHT JOIN Table1Info AS 0 ON [1].[Recruited By] = [0].ID) LEFT JOIN (((((((Table1Info AS 10 RIGHT JOIN Table1Info AS 9 ON [10].[Recruited By] = [9].ID) RIGHT JOIN Table1Info AS 8 ON [9].[Recruited By] = [8].ID) RIGHT JOIN Table1Info AS 7 ON [8].[Recruited By] = [7].ID) RIGHT JOIN Table1Info AS 6 ON [7].[Recruited By] = [6].ID) RIGHT JOIN Table1Info AS 5 ON [6].[Recruited By] = [5].ID) RIGHT JOIN Table1Info AS 4 ON [5].[Recruited By] = [4].ID) RIGHT JOIN Table1Info AS 3 ON [4].[Recruited By] = [3].ID) ON [2].ID = [3].[Recruited By]) LEFT JOIN Table1Info AS 11 ON [10].ID = [11].[Recruited By]
  3. WHERE ((([11].ID) Is Null));
VBA
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Function ColumnEnd(Col0, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11) As Integer
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.           If Col11 <> 0 Then
  12.  
  13.                  ColumnEnd = Col11
  14.  
  15.                  Exit Function
  16.  
  17.          End If
  18.  
  19.          If Col10 <> 0 Then
  20.  
  21.                  ColumnEnd = Col10
  22.  
  23.                  Exit Function
  24.  
  25.          End If
  26.  
  27.                   If Col9 <> 0 Then
  28.  
  29.                  ColumnEnd = Col9
  30.  
  31.                  Exit Function
  32.  
  33.          End If
  34.  
  35.                   If Col8 <> 0 Then
  36.  
  37.                  ColumnEnd = Col8
  38.  
  39.                  Exit Function
  40.  
  41.          End If
  42.  
  43.                   If Col7 <> 0 Then
  44.  
  45.                  ColumnEnd = Col7
  46.  
  47.                  Exit Function
  48.  
  49.          End If
  50.  
  51.                   If Col6 <> 0 Then
  52.  
  53.                  ColumnEnd = Col6
  54.  
  55.                  Exit Function
  56.  
  57.          End If
  58.  
  59.                   If Col5 <> 0 Then
  60.  
  61.                  ColumnEnd = Col5
  62.  
  63.                  Exit Function
  64.  
  65.          End If
  66.  
  67.                   If Col4 <> 0 Then
  68.  
  69.                  ColumnEnd = Col4
  70.  
  71.                  Exit Function
  72.  
  73.          End If
  74.  
  75.                   If Col3 <> 0 Then
  76.  
  77.                  ColumnEnd = Col3
  78.  
  79.                  Exit Function
  80.  
  81.          End If
  82.  
  83.                   If Col2 <> 0 Then
  84.  
  85.                  ColumnEnd = Col2
  86.  
  87.                  Exit Function
  88.  
  89.          End If
  90.  
  91.                   If Col1 <> 0 Then
  92.  
  93.                  ColumnEnd = Col1
  94.  
  95.                  Exit Function
  96.  
  97.          End If
  98.  
  99.                   If Col0 <> 0 Then
  100.  
  101.                  ColumnEnd = ColBase
  102.  
  103.                  Exit Function
  104.  
  105.          End If
  106.  
  107.  
  108. End Function
  109.  
its very strange considering, i can open it in design view and it works just fine. it only happens after viewing the query and pulling it back into design.

anybody see where the problem is? also, i am using access 2007. hopefully this isn't a 2007 bug.
Mar 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Paul | last post by:
Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: Richard | last post by:
In a manufacturing document control situation, a procedure revision table named has principal columns and and satellite data columns , , . A unique index and to ensure each procedure name has...
2
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php"...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
1
by: steveyell | last post by:
Hi there, I have a database with 90,000 property records and I need to split the database into 5 geographic areas. Those areas are defined by postcode districts, and a number of postcode...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.