473,395 Members | 1,745 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,395 software developers and data experts.

convert query sql to SQLServer sql

Hi All,

I have this query which updates a field based on the result of an IIF
statement. The table is on SQLServer and I'm linked to it and it has
many records and will take Access a very long time to run so I'm
thinking I can make this query a pass-thru query and I hope someone
can write the proper SQLServer SQL for this Access SQL
I know I have to change the IIF to Case When Else but I haven't been
able to get it figured out yet.

UPDATE tblHospLineFinal SET tblHospLineFinal.RemarkCode =
IIf(Not IsNull(tblHospLineFinal!ResubEOR),tblHospLineFinal !ResubEOR,
IIf(Not IsNull(tblHospLineFinal!EOB3Line),tblHospLineFinal !EOB3Line,
IIf(Not IsNull(tblHospLineFinal!EOB2Line),tblHospLineFinal !
EOB2Line,tblHospLineFinal!EOB1Line)));

thanks
bobh.

Nov 1 '07 #1
5 2708
Greetings,

since your query is not linked to any additional tables and there is no
Where clause, then you are updating your table to just one value. You
can simplify your query by extracting the value first and then passing
that value into your Update query

Value = DLookup or DSum, Dcount, ...

Update tblx Set fld1 = value

or

Update tblx Set fld1 = value where fldy is not null

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 1 '07 #2

"bobh" <vu******@yahoo.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
Hi All,

I have this query which updates a field based on the result of an IIF
statement. The table is on SQLServer and I'm linked to it and it has
many records and will take Access a very long time to run so I'm
thinking I can make this query a pass-thru query and I hope someone
can write the proper SQLServer SQL for this Access SQL
I know I have to change the IIF to Case When Else but I haven't been
able to get it figured out yet.

UPDATE tblHospLineFinal SET tblHospLineFinal.RemarkCode =
IIf(Not IsNull(tblHospLineFinal!ResubEOR),tblHospLineFinal !ResubEOR,
IIf(Not IsNull(tblHospLineFinal!EOB3Line),tblHospLineFinal !EOB3Line,
IIf(Not IsNull(tblHospLineFinal!EOB2Line),tblHospLineFinal !
EOB2Line,tblHospLineFinal!EOB1Line)));

thanks
bobh.
It may be quicker run 5 querys using the test in you IIF for the WHERE
clause.

But why would you want to copy data from 1 column of a table to another for
all rows of your table? Unless you were reformatting the data?
Nov 1 '07 #3
UPDATE tblHospLineFinal

SET tblHospLineFinal.RemarkCode =
CASE
IIf(Not IsNull(tblHospLineFinal!ResubEOR),tblHospLineFinal !ResubEOR,
IIf(Not IsNull(tblHospLineFinal!EOB3Line),tblHospLineFinal !EOB3Line,
IIf(Not IsNull(tblHospLineFinal!EOB2Line),tblHospLineFinal !
EOB2Line,tblHospLineFinal!EOB1Line)));

On Nov 1, 1:20 pm, bobh <vulca...@yahoo.comwrote:
Hi All,

I have this query which updates a field based on the result of an IIF
statement. The table is on SQLServer and I'm linked to it and it has
many records and will take Access a very long time to run so I'm
thinking I can make this query a pass-thru query and I hope someone
can write the proper SQLServer SQL for this Access SQL
I know I have to change the IIF to Case When Else but I haven't been
able to get it figured out yet.

UPDATE tblHospLineFinal SET tblHospLineFinal.RemarkCode =
IIf(Not IsNull(tblHospLineFinal!ResubEOR),tblHospLineFinal !ResubEOR,
IIf(Not IsNull(tblHospLineFinal!EOB3Line),tblHospLineFinal !EOB3Line,
IIf(Not IsNull(tblHospLineFinal!EOB2Line),tblHospLineFinal !
EOB2Line,tblHospLineFinal!EOB1Line)));

thanks
bobh.

Nov 2 '07 #4
UPDATE tblHospLineFinal

SET
tblHospLineFinal.RemarkCode =
CASE
WHEN ResubEOR is not null THEN ResubEOR
WHEN EOB3Line is not null then EOB3Line
WHEN EOB2Line is not null then EOB2Line
ELSE EOB1LINE
end
OR:
UPDATE tblHospLineFinal

SET
tblHospLineFinal.RemarkCode = coalesce
(ResubEOR,EOB3Line,EOB2Line,EOB1LINE,'Unknown')

Chris Nebinger

On Nov 1, 1:20 pm, bobh <vulca...@yahoo.comwrote:
Hi All,

I have this query which updates a field based on the result of an IIF
statement. The table is on SQLServer and I'm linked to it and it has
many records and will take Access a very long time to run so I'm
thinking I can make this query a pass-thru query and I hope someone
can write the proper SQLServer SQL for this Access SQL
I know I have to change the IIF to Case When Else but I haven't been
able to get it figured out yet.

UPDATE tblHospLineFinal SET tblHospLineFinal.RemarkCode =
IIf(Not IsNull(tblHospLineFinal!ResubEOR),tblHospLineFinal !ResubEOR,
IIf(Not IsNull(tblHospLineFinal!EOB3Line),tblHospLineFinal !EOB3Line,
IIf(Not IsNull(tblHospLineFinal!EOB2Line),tblHospLineFinal !
EOB2Line,tblHospLineFinal!EOB1Line)));

thanks
bobh.

Nov 2 '07 #5
Both these approaches were returning nulls in the RemarkCode field.
After playing with these for a long while and not having any success
at getting them to work and I believed they should have worked. I
finally discovered that the SQL table that the dba setup on the
SQLServer has 'Allow zero lenght strings' set to yes on all the text
fields. After writing some vba code and checking for nulls it didn't
find any nulls changed the code to find Len(RemarkCode)>0 it didn't
find any so, I changed your
Case logic to say
WHEN Len(ResubEOR)>0 THEN ResubEOR

Bingo! it worked perfectly........ thanks for your help and
steering me in the right direction.
bobh.

On Nov 1, 9:00 pm, "chris.nebin...@gmail.com"
<chris.nebin...@gmail.comwrote:
UPDATE tblHospLineFinal

SET
tblHospLineFinal.RemarkCode =
CASE
WHEN ResubEOR is not null THEN ResubEOR
WHEN EOB3Line is not null then EOB3Line
WHEN EOB2Line is not null then EOB2Line
ELSE EOB1LINE
end

OR:

UPDATE tblHospLineFinal

SET
tblHospLineFinal.RemarkCode = coalesce
(ResubEOR,EOB3Line,EOB2Line,EOB1LINE,'Unknown')

Chris Nebinger

On Nov 1, 1:20 pm,bobh<vulca...@yahoo.comwrote:
Hi All,
I have this query which updates a field based on the result of an IIF
statement. The table is on SQLServer and I'm linked to it and it has
many records and will take Access a very long time to run so I'm
thinking I can make this query a pass-thru query and I hope someone
can write the proper SQLServer SQL for this Access SQL
I know I have to change the IIF to Case When Else but I haven't been
able to get it figured out yet.
UPDATE tblHospLineFinal SET tblHospLineFinal.RemarkCode =
IIf(Not IsNull(tblHospLineFinal!ResubEOR),tblHospLineFinal !ResubEOR,
IIf(Not IsNull(tblHospLineFinal!EOB3Line),tblHospLineFinal !EOB3Line,
IIf(Not IsNull(tblHospLineFinal!EOB2Line),tblHospLineFinal !
EOB2Line,tblHospLineFinal!EOB1Line)));
thanks
bobh.- Hide quoted text -

- Show quoted text -

Nov 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anabella | last post by:
Hi all, is there any tool which is capable to convert query initially written for msaccess database to query for mssql server. I have tons of queries which contains iif, trim and similar...
3
by: John | last post by:
Anyone have any tips on how to "convert" queries created in the Query By Design to SQL for VBA in Access? I particularly have difficulties with all of the quotation marks involved with parameters...
1
by: Terri | last post by:
These queries work in SQL Server but not in Access. Can anyone see how I can modify these so they will work in A2K SELECT A.AdId, COUNT(DISTINCT I.ImpressionId) AS Impressions, COUNT(DISTINCT...
3
by: Devonish | last post by:
I am planning to convert an existing Access database which has a back end (data tables and relationships only) on a server and a copy of the front end (form, queries, reports) on each of about a...
29
by: Jan | last post by:
Hi: I have an Access database that's been running (in one form or another) for a couple of different clients for a few years. Now a new client has requested that it be implemented with a SQL...
11
by: kirpi | last post by:
There is an SQLServer database somewhere, and I would like to grab and publish some data to my web pages. I was told: "please, do", and given server address, database name, id, and password. My...
1
by: ashishtech | last post by:
In the following query D_CNT_LINE_EXPIRE comparison with '2008-09-19' is failing altough value is there in this field. D_CNT_LINE_EXPIRE is a timestamp field in SQLSERVER table CCG03. I doubt...
1
by: Michel Walsh | last post by:
In the same spirit, but more LINQ related, you can also use ExecuteQuery: var query = dataContext.ExecuteQuery<className>( @"SELECT ... WHERE ... AND... OR... "); where className is...
1
by: osman7king | last post by:
hello all... I'm trying to convert the query which uses outer join statment from Oracle to PostgreSQL but I have some problems with this query may some one help me for this problem? SELECT ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.