How Do I Write This SQL Statement?
Sep 11, 2007
I have a table named "products", it has a column called "category", I have data such as "CategoryA", "CategoryB" and "CategoryC" etc.... now I want to do a select statement and choose "CategoryA" and "CategoryB" but I want to rename them as "A" and "B". how do I write such a statement... thanks!
View 9 Replies
ADVERTISEMENT
Jul 4, 2006
Hello friends,
I want to use select statement in a CASE inside procedure.
can I do it? of yes then how can i do it ?
following part of the procedure clears my requirement.
SELECT E.EmployeeID,
CASE E.EmployeeType
WHEN 1 THEN
select * from Tbl1
WHEN 2 THEN
select * from Tbl2
WHEN 3 THEN
select * from Tbl3
END
FROM EMPLOYEE E
can any one help me in this?
please give me a sample query.
Thanks and Regards,
Kiran Suthar
View 7 Replies
View Related
Feb 8, 2008
I wanted to select few columns from the result of calling this store procedure and sort by a column.
{CALL FIQR.Portfolio.Loans_In_Portfolio('2007-09-07', 'FISYND', '', '%')}
How should I write it?(without changing the store procedure)
View 8 Replies
View Related
Apr 29, 2005
i have those columns: id, no, description.
View 3 Replies
View Related
Dec 14, 2006
Hi all,
DECLARE @STA as char(50)
SET @STA = 'TT'
SELECT * FROM ABC_TBL where ABC_Filed in (@STA)
if i have multivalue in parameter @STA, like 'TT', 'DD', 'AA'
so how can i write my statement? i only need to pass one parameter with multilist, so do anybody know how to write the MS sql statement?
Example like
DECLARE @STA as char(50)
SET @STA = 'TT', 'DD'
SELECT * FROM ABC_TBL where ABC_Filed in (@STA)
Thank You.
Regards,
S3ng
View 3 Replies
View Related
Jul 26, 2007
I want to write a select statement that will show only distinct Student IDs where every record in the table with that student id has a grade above 80?
Lets say for example the table looks like this:
Student_ID
Grade
11276
93
56879
81
11276
76
44327
92
11276
84
56879
97
56879
82 The select statement should only show students, 56879 & 44327 because student 11276 made a 76 in one class.Anyone know how to word this select statement?Thanks for any help!
View 8 Replies
View Related
May 9, 2007
I have a table with two columns. empnum and empname. there are some data with same empnum but different empname. I just want to get the first empname for the same empnum. Is there a way to write a sql stetment to do this?
Thanks
View 3 Replies
View Related
Aug 20, 2007
Hi guys
I'll appreciate any help with the following problem:
Table 1: TBSALESHEADER
PK: SALESNO
Table 2: TBSALESENTRY
FK: SALESNO
This query is return 2 rows.
SELECT PAYMTDID AS TYPE, CONVERT(CHAR(8),SALESDATE,112) AS DATE, SUM(SALESAMT) AS AMOUNT FROM TBSALESHEADER A, TBSALESENTRY B WHERE A.SALESNO = B.SALESNO AND CONVERT(CHAR(8),SALESDATE,112) = '20070701'
GROUP BY PAYMTDID,CONVERT(CHAR(8),SALESDATE,112)
TYPE DATE AMOUNT
----------------------------------------------------------
0 20070701 3041.29
1 20070701 1442.20
Issue:
Instead of retrieving 2 rows showing 2 type of records, I want to display the 2 type in 2 columns (need to return in 1 row).
Can I get this desired result as following in 1 query statement:
DATE AMOUNT (TYPE 1) AMOUNT (TYPE 2)
---------------------------------------------------------------------------------
20070701 3041.29 1442.20
Please help.
Thanks.
View 5 Replies
View Related
Aug 1, 2007
I'm running a select statement from within my VB.net code. However, if the software package name that I chose from a drop down list in my form is not available in the search (in the TableColumn called Software.Package_Name), I would like to be able to write the message "Record Not Found" to the Package_Name "ListBox" column.
Here's the select statement:
"SELECT n.Workstation_Name , s.install_status , s.install_date , s.name , s.version , s.build , s.Package_Name , n.city , n.state FROM software s , network n where ( s.mac=n.mac AND n.Workstation_Name='B001617CA709E' ) AND ( s.name='Adobe Reader' AND s.Install_status='1') ORDER BY n.Workstation_Name ASC"
My ListBox control is named lstQueryResults and uses a Structure that is one to one with each row of the lstQueryResults control.
i.e.
Public Class LIST_CTRL_DATA
Public WksName As String
Public InstallStatus As String
Public InstallDate As String
Public PackageName As String
Public AppName As String
Public Version As String
Public Build As String
Public City As String
Public State As String
Public Percent As UInteger
Finally, here's the While..End routine that plugs the data into the ListBox called lstQueryResults.
While sqlReader.Read()
currec += 1
Dim msg As THREAD_MESSAGE
msg.msgid = 101
Dim message As New LIST_CTRL_DATA
message.WksName = sqlReader("Workstation_Name").ToString
message.InstallStatus = sqlReader("Install_Status").ToString
message.InstallDate = sqlReader("Install_Date").ToString
message.AppName = sqlReader("Name").ToString
message.Version = sqlReader("Version").ToString
message.Build = sqlReader("Build").ToString
message.PackageName = sqlReader("Package_Name").ToString
message.City = sqlReader("City").ToString
message.State = sqlReader("State").ToString
message.Percent = (currec * 100) / maxrecs
msg.msgdata = message
m_ParentWindow.Invoke(m_NotifyMainWindow, msg)
End While
Any ideas on whether or not you can write an If..Then Else statement within the SQL Select Statement and if so how?
I'm still somewhat new to SQL. Any assistance would be great.
Regards,
NBK
View 1 Replies
View Related
Sep 26, 2007
I create a table that is named T1(C1,C2) and insert some data,as following:
C1 C2
1 1
4 NULL
NULL 5
7 NULL
NULL 9
12 12
14 NULL
NULL 16
I want to write a select statement to obtain the following result:
C1 C2
1 1
4 5
7 9
12 12
14 16
how to write the select statement?
View 2 Replies
View Related
Apr 3, 2013
I am running SQL Server 2000 and need to know how to write an IF else statement with a variable for a table name. I am constantly getting errors when I attempt this feat.
Code:
Use [TestDatabase]
Go
CREATE PROCEDURE UserInputAsTable
[code]....
View 14 Replies
View Related
Oct 30, 2012
I have a case statement as follows which I am using in the where clause to get today's data
(Case when (A.ID is null or B.ID = '' or C.ID= ' ') Then convert(varchar,(Case when A.Time is null then B.Time else A.Time end),103)
else convert(varchar,(Case when A.Time is null then ''" else B.Time end),103) end)
=convert(varchar,getDATE(),103)
However I want to know whether I can use a date range on a case statement
I.e. I want to be able to use BETWEEN statement to get a date range
BETWEEN convert(varchar,getDATE(),103) AND convert(varchar,getDATE()-1,103)
How do I achieve this on a CASE WHEN statement?
View 3 Replies
View Related
Sep 19, 2013
I have to do following scenario,
if 1st query Then 2nd Query
Else 'Msg'
How Can i do this using Case Statement??how can do this by Other way??
View 5 Replies
View Related
Oct 6, 2007
Hi all,
We are retriving tables from DB2 and loading into a SQL server. while retriving temporary tables are getting created in the linked server. we need to delete the data in those temporary tables in Linked server. I don't know how to write delete statement for the tables in linked server. any pointers would be appreciated.
Thanks in advance.
Shriram
View 1 Replies
View Related
Mar 29, 2008
col1 col2 col3 col4
36930.60 145 N . 00
17618.43 190 N . 00
6259.20 115 N .00
8175.45 19 N .00
18022.54 212 N .00
111.07 212 B .00
13393.05 67 N .00
In above 4 col
if col3 value is B then cursor has to fectch appropriate value from col4.
if col3 value is N then cursor has to fectch appropriate value from col1.
here col2 values are unique.
Can any one reply for this..............
View 3 Replies
View Related
Dec 7, 2004
Edited by SomeNewKid. Please post code between <code> and </code> tags.
// Pls copy the following HTML after that you generate the HTML page. Then you will know what I mean. I need to form "New Table" from Job Revence and Job Cost using SQL statement? thx
-----------The following code-----------------
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=big5">
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=Big5">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 9">
<link rel=File-List href="cid:filelist.xml@01C4DA4E.7D08F5E0">
<!--[if !mso]>
<style>
v:* {behavior:url(#default#VML);}
o:* {behavior:url(#default#VML);}
x:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
.xl15
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:????;
mso-generic-font-family:auto;
mso-font-charset:136;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl22
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:????;
mso-generic-font-family:auto;
mso-font-charset:136;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl23
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:????;
mso-generic-font-family:auto;
mso-font-charset:136;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
background:#339966;
mso-pattern:auto none;
white-space:nowrap;}
.xl24
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:700;
font-style:normal;
text-decoration:none;
font-family:????, serif;
mso-font-charset:136;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet1</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>225</x:DefaultRowHeight>
<x:Print>
<x:ValidPrinterInfo/>
<x:PaperSizeIndex>9</x:PaperSizeIndex>
<x:HorizontalResolution>-3</x:HorizontalResolution>
<x:VerticalResolution>0</x:VerticalResolution>
</x:Print>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveCol>10</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>10470</x:WindowHeight>
<x:WindowWidth>16755</x:WindowWidth>
<x:WindowTopX>240</x:WindowTopX>
<x:WindowTopY>30</x:WindowTopY>
<x:HasEnvelope/>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body>
<table x:str border=0 cellpadding=0 cellspacing=0 width=636 style='border-collapse:
collapse;table-layout:fixed;width:477pt'>
<col width=56 span=7 style='width:42pt'>
<col width=104 style='mso-width-source:userset;mso-width-alt:4437;width:78pt'>
<col width=140 style='mso-width-source:userset;mso-width-alt:5973;width:105pt'>
<tr height=22 style='height:16.5pt'>
<td height=22 class=xl24 colspan=2 width=112 style='height:16.5pt;mso-ignore:
colspan;width:84pt'>JOB TABLE</td>
<td class=xl15 width=56 style='width:42pt'></td>
<td class=xl15 width=56 style='width:42pt'></td>
<td class=xl15 width=56 style='width:42pt'></td>
<td class=xl15 width=56 style='width:42pt'></td>
<td class=xl15 width=56 style='width:42pt'></td>
<td class=xl15 width=104 style='width:78pt'></td>
<td class=xl15 width=140 style='width:105pt'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl23 style='height:11.25pt'>JobNo</td>
<td colspan=8 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td>
<td colspan=8 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=22 style='height:16.5pt'>
<td height=22 class=xl22 style='height:16.5pt;border-top:none'>SE0002</td>
<td colspan=5 class=xl15 style='mso-ignore:colspan'></td>
<td class=xl24 colspan=2 style='mso-ignore:colspan'>New Table</td>
<td class=xl15></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 colspan=6 class=xl15 style='height:11.25pt;mso-ignore:colspan'></td>
<td class=xl23>JobNo</td>
<td class=xl23 style='border-left:none'>no of Revence</td>
<td class=xl23 style='border-left:none'>no of Cost</td>
</tr>
<tr height=22 style='height:16.5pt'>
<td height=22 class=xl24 colspan=2 style='height:16.5pt;mso-ignore:colspan'>JOB
Revence</td>
<td colspan=4 class=xl15 style='mso-ignore:colspan'></td>
<td class=xl22 style='border-top:none'>SE0001</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>2</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl23 style='height:11.25pt'>JobNo</td>
<td class=xl23 style='border-left:none'>ItemNo</td>
<td colspan=4 class=xl15 style='mso-ignore:colspan'></td>
<td class=xl22 style='border-top:none'>SE0002</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>0</td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td>
<td colspan=7 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>2</td>
<td colspan=7 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0002</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td>
<td colspan=7 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 colspan=9 class=xl15 style='height:11.25pt;mso-ignore:colspan'></td>
</tr>
<tr height=22 style='height:16.5pt'>
<td height=22 class=xl24 colspan=2 style='height:16.5pt;mso-ignore:colspan'>JOB
Cost</td>
<td colspan=7 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl23 style='height:11.25pt'>JobNo</td>
<td class=xl23 style='border-left:none'>ItemNo</td>
<td colspan=7 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<tr height=15 style='height:11.25pt'>
<td height=15 class=xl22 style='height:11.25pt;border-top:none'>SE0001</td>
<td class=xl22 align=right style='border-top:none;border-left:none' x:num>1</td>
<td colspan=7 class=xl15 style='mso-ignore:colspan'></td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=56 style='width:42pt'></td>
<td width=56 style='width:42pt'></td>
<td width=56 style='width:42pt'></td>
<td width=56 style='width:42pt'></td>
<td width=56 style='width:42pt'></td>
<td width=56 style='width:42pt'></td>
<td width=56 style='width:42pt'></td>
<td width=104 style='width:78pt'></td>
<td width=140 style='width:105pt'></td>
</tr>
<![endif]>
</table>
</body>
</html>
View 2 Replies
View Related
Nov 6, 2007
I'm sure this is a very simple piece of code, but I'm having trouble understanding how to do this.
First I have a database with three columns
ContactID
View 1 Replies
View Related
Jan 26, 2007
I want to write a statement something like this
SELECT Add_Date, File_No FROM dbo.File_Storage WHERE (File_No = 11/11/1234/)
But i want the search to ignore the first 2 digits so that it will return e.g
10/11/1234, 09/11/1234 so that it's only matching the last part
Any Help Would be greatly appreciated Thanks
View 6 Replies
View Related
Feb 23, 2015
I have the linked server connection created and works perfectly well. I mean I am able to see the tables while I am on my database.
how do I write a SQL statement to reference the linked server ?
I tried the following:
Select top 100 * from casmpogdbspr1.MPOG_Collations.dbo.AsaClass_Cleaned
Then I get the error message....
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI10" for linked server "casmpogdbspr1" does not contain the table ""MPOG_Collations"."dbo"."AsaClass_Cleaned"". The table either does not exist or the current user does not have permissions on that table.
View 2 Replies
View Related
Jul 24, 2012
Write a CREATE VIEW statement that defines a view named Invoice Basic that returns three columns: VendorName, InvoiceNumber, and InvoiceTotal. Then, write a SELECT statement that returns all of the columns in the view, sorted by VendorName, where the first letter of the vendor name is N, O, or P.
This is what I have so far,
CREATE VIEW InvoiceBasic AS
SELECT VendorName, InvoiceNumber, InvoiceTotal
From Vendors JOIN Invoices
ON Vendors.VendorID = Invoices.VendorID
[code]...
View 2 Replies
View Related
Jul 12, 2006
Hi,
I tried to backup the master key by the following syntax :
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'mypassword'
BACKUP MASTER KEY TO FILE = 'c: empmaster' ENCRYPTION BY PASSWORD = 'mypassword'
but it failed and i got the following message:
Cannot write into file 'c: empmaster'. Verify that you have write permissions, that the file path is valid, and that the file does not already exist.
NB: I am using the "sa" user to execute this command.
I know that we have a security permission issue , but where and how ?
Regards,
Tarek Ghazali
SQL Server MVP
View 12 Replies
View Related
Aug 29, 2006
I am currently having this problem with gridview and detailview. When I drag either onto the page and set my select statement to pick from one table and then update that data through the gridview (lets say), the update works perfectly. My problem is that the table I am pulling data from is mainly foreign keys. So in order to hide the number values of the foreign keys, I select the string value columns from the tables that contain the primary keys. I then use INNER JOIN in my SELECT so that I only get the data that pertains to the user I am looking to list and edit. I run the "test query" and everything I need shows up as I want it. I then go back to the gridview and change the fields which are foreign keys to templates. When I edit the templates I bind the field that contains the string value of the given foreign key to the template. This works great, because now the user will see string representation instead of the ID numbers that coinside with the string value. So I run my webpage and everything show up as I want it to, all the data is correct and I get no errors. I then click edit (as I have checked the "enable editing" box) and the gridview changes to edit mode. I make my changes and then select "update." When the page refreshes, and the gridview returns, the data is not updated and the original data is shown. I am sorry for so much typing, but I want to be as clear as possible with what I am doing. The only thing I can see being the issue is that when I setup my SELECT and FROM to contain fields from multiple tables, the UPDATE then does not work. When I remove all of my JOIN's and go back to foreign keys and one table the update works again. Below is what I have for my SQL statements:------------------------------------------------------------------------------------------------------------------------------------- SELECT:SELECT People.FirstName, People.LastName, People.FullName, People.PropertyID, People.InviteTypeID, People.RSVP, People.Wheelchair, Property.[House/Day Hab], InviteType.InviteTypeName FROM (InviteType INNER JOIN (Property INNER JOIN People ON Property.PropertyID = People.PropertyID) ON InviteType.InviteTypeID = People.InviteTypeID) WHERE (People.PersonID = ?)UPDATE:UPDATE [People] SET [FirstName] = ?, [LastName] = ?, [FullName] = ?, [PropertyID] = ?, [InviteTypeID] = ?, [RSVP] = ?, [Wheelchair] = ? WHERE [PersonID] = ? ---------------------------------------------------------------------------------------------------------------------------------------The only fields I want to update are in [People]. My WHERE is based on a control that I use to select a person from a drop down list. If I run the test query for the update while setting up my data source the query will update the record in the database. It is when I try to make the update from the gridview that the data is not changed. If anything is not clear please let me know and I will clarify as much as I can. This is my first project using ASP and working with databases so I am completely learning as I go. I took some database courses in college but I have never interacted with them with a web based front end. Any help will be greatly appreciated.Thank you in advance for any time, help, and/or advice you can give.Brian
View 5 Replies
View Related
Jan 9, 2015
Ok I have a query "SELECT ColumnNames FROM tbl1" let's say the values returned are "age,sex,race".
Now I want to be able to create an "update" statement like "UPATE tbl2 SET Col2 = age + sex + race" dynamically and execute this UPDATE statement. So, if the next select statement returns "age, sex, race, gender" then the script should create "UPDATE tbl2 SET Col2 = age + sex + race + gender" and execute it.
View 4 Replies
View Related
Jul 20, 2005
hiI need to write a stored procedure that takes input parameters,andaccording to these parameters the retrieved fields in a selectstatement are chosen.what i need to know is how to make the fields of the select statementconditional,taking in consideration that it is more than one fieldaddedfor exampleSQLStmt="select"if param1 thenSQLStmt=SQLStmt+ field1end ifif param2 thenSQLStmt=SQLStmt+ field2end if
View 2 Replies
View Related
Oct 29, 2007
Hi guys,
I have the query below (running okay):
Code Block
SELECT DISTINCT Field01 AS 'Field01', Field02 AS 'Field02'
FROM myTables
WHERE Conditions are true
ORDER BY Field01
The results are just as I need:
Field01 Field02
------------- ----------------------
192473 8461760
192474 22810
Because other reasons. I need to modify that query to:
Code Block
SELECT DISTINCT Field01 AS 'Field01', Field02 AS 'Field02'
INTO AuxiliaryTable
FROM myTables
WHERE Conditions are true
ORDER BY Field01
SELECT DISTINCT [Field02] FROM AuxTable
The the results are:
Field02
----------------------
22810
8461760
And what I need is (without showing any other field):
Field02
----------------------
8461760
22810
Is there any good suggestion?
Thanks in advance for any help,
Aldo.
View 3 Replies
View Related
Nov 5, 2015
I've have a need with SQL Server 2005 (so I've no MERGE statement), I have to merge 2 tables, the target table has 10 fields, the first 4 are the clustered index and primary key, the source table has the same fields and index.Since I can't use the MERGE statement (I'm in SQL 2005) I have to make a double step operation, and INSERT and an UPDATE, I can't figure how to design the WHERE condition for the insert statement.
View 2 Replies
View Related
Aug 13, 2014
i was tasked to created an UPDATE statement for 6 tables , i would like to update 4 columns within the 6 tables , they all contains the same column names. the table gets its information from the source table, however the data that is transferd to the 6 tables are sometimes incorrect , i need to write a UPDATE statement that will automatically correct the data. the Update statement should also contact a where clause
the columns are [No] , [Salesperson Code], [Country Code] and [Country Name]
i was thinking of doing
Update [tablename]
SET [No] =
CASE
WHEN [No] ='AF01' THEN 'Country Code' = 'ZA7' AND 'Country Name' = 'South Africa'
ELSE 'Null'
END
What is the best way to script this
View 1 Replies
View Related
May 5, 2015
I am attempting to run update statements within a SELECT CASE statement.
Select case x.field
WHEN 'XXX' THEN
UPDATE TABLE1
SET TABLE1.FIELD2 = 1
ELSE
UPDATE TABLE2
SET TABLE2.FIELD1 = 2
END
FROM OuterTable x
I get incorrect syntax near the keyword 'update'.
View 7 Replies
View Related
Feb 4, 2006
I am using ASP.NET 2.0, and am attempting to write some code to connect to the database and query a data table. The compiler is not recognizing my SqlConnection statement. It does recognize other commands. And just to make sure, I created other sql objects such as ObjectDataSource and SqlDataSource. The compiler does not find a problem with that code.
Basically the compiler is telling me that I am missing a "using" directive. The compiler is wrong though, because I am including the statement "usingSystemData" Can someone please take a look at my code below and to see if you notice what the problem might be? Note that I numbered the lines of code below. Note that I also tried putting lines 3 trhough 6 before line 2(The page directive) but that did not fix the problem The compiler still gives me the same compiler message.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request.Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)Source Error:
Line 21: SqlConnection sqlConn = new SqlConnection("server=localhost;uid=sa;pwd=password;database=master;");
1 <asp:sqldatasource runat="server"></asp:sqldatasource>
2 <%@ Page Language="C#"%>
3 using System;
4 using System.Data;
5 using System.Collections;
6 using System.Data.SqlClient;
7
8 <script runat=server>
9
10 protected void Page_Load(object o, EventArgs e)
11 {
12 ObjectDataSource dsa; // This works no problems from the compiler here
13 SqlDataSource ds; // This works no problems from the compiler
14
15 if (IsPostBack)
16 {
17 if (AuthenticateUser(txtUsername.Text,txtPassword.Text))
18 {
19 instructions.Text = "Congratulations, your authenticated!";
20 instructions.ForeColor = System.Drawing.Color.Red;
21 SqlConnection sqlConn = new SqlConnection("server=localhost;uid=sa;pwd=password;database=master;");
22 String sqlStmt = "Select UserName from LogIn where UserName='" + txtUsername.Text + "' and password='" + sHashedPassword + "'";
23 }
24 else
25 {
26 instructions.Text = "Please try again!";
27 instructions.ForeColor = System.Drawing.Color.Red;
28 }
29 }
30
31 }
32
33 bool AuthenticateUser(string username, string password)
34 {
35 // Authentication code goes here
36
37 }
View 1 Replies
View Related
May 26, 2006
Hi All,
I've looked through the forum hoping I'm not the only one with this issue but alas, I have found nothing so I'm hoping someone out there will give me some assistance.
My problem is the case statement in my Insert Statement. My overall goal is to insert records from one table to another. But I need to be able to assign a specific value to the incoming data and thought the case statement would be the best way of doing it. I must be doing something wrong but I can't seem to see it.
Here is my code:
Insert into myTblA
(TblA_ID,
mycasefield =
case
when mycasefield = 1 then 99861
when mycasefield = 2 then 99862
when mycasefield = 3 then 99863
when mycasefield = 4 then 99864
when mycasefield = 5 then 99865
when mycasefield = 6 then 99866
when mycasefield = 7 then 99867
when mycasefield = 8 then 99868
when mycasefield = 9 then 99855
when mycasefield = 10 then 99839
end,
alt_min,
alt_max,
longitude,
latitude
(
Select MTB.LocationID
MTB.model_ID
MTB.elevation, --alt min
null, --alt max
MTB.longitude, --longitude
MTB.latitude --latitude
from MyTblB MTB
);
The error I'm getting is:
Incorrect syntax near '='.
I have tried various versions of the case statement based on examples I have found but nothing works.
I would greatly appreciate any assistance with this one. I've been smacking my head against the wall for awhile trying to find a solution.
View 10 Replies
View Related
Oct 20, 2014
In the below code i want to use select statement for getting customer
address1,customeraddress2,customerphone,customercity,customerstate,customercountry,customerfirstname,customerlastname
from customer table.Rest of the things will be as it is in the following code.How do i do this?
INSERT INTO EMImportListing ("
sql += " CustId,Title,Description,JobCity,JobState,JobPostalCode,JobCountry,URL,Requirements, "
sql += " IsDraft,IsFeatured,IsApproved,"
sql += " Email,OrgName,customerAddress1,customerAddress2,customerCity,customerState,customerPostalCode,
[code]....
View 1 Replies
View Related
Feb 20, 2008
i want to display records as per if else condition in ms sql query,for this i have used tables ,queries as follows
as per data in MS Sql
my tables are as follows
1)material
fields are -- material_id,project_type,project_id,qty, --
2)AB_Corporate_project
fields are-- ab_crp_id,custname,contract_no,field_no
3)Other_project
fields are -- other_proj_id,other_custname,po
for ex :
vales in table's are
AB_Corporate_project
=====================
ab_crp_id custname contract_no field_no
1 abc 234 66
2 xyz 33 20
Other_project
============
other_proj_id other_custname po
1 xxcx 111
2 dsd 222
material
=========
material_id project_type project_id qty
1 AB Corporate 1 3
2 Other Project 2 7
i have taken AB Corporate for AB_Corporate_project ,Other Project for Other_project
sample query i write :--
select m.material_id ,m.project_type,m.project_id,m.qty,ab.ab_crp_id,
ab.custname ,op.other_proj_id,op.other_custname,op. po
case if m.project_type = 'AB Corporate' then
select * from AB_Corporate_project where ab.ab_crp_id = m.project_id
else if m.project_type = 'Other Project' then
select * from Other_project where op.other_proj_id=m.project_id
end
from material m,AB_Corporate_project ab,Other_project op
but this query not work,also it gives errors
i want sql query to show data as follows
material_id project_type project_id custname other_custname qty
1 AB Corporate 1 abc -- 3
2 Other Project 2 -- dsd 7
so plz help me how can i write sql query for to show the output
plz send a sql query
View 8 Replies
View Related
Aug 10, 2006
I have 3 tables, with this relation:
tblChats.WebsiteID = tblWebsite.ID
tblWebsite.AccountID = tblAccount.ID
I need to delete rows within tblChats where tblChats.StartTime - GETDATE() < 180 and where they are apart of @AccountID. I have this select statement that works fine, but I am having trouble converting it to a delete statement:
SELECT * FROM tblChats c
LEFT JOIN tblWebsites sites ON sites.ID = c.WebsiteID
LEFT JOIN tblAccounts accounts on accounts.ID = sites.AccountID
WHERE accounts.ID = 16 AND GETDATE() - c.StartTime > 180
View 1 Replies
View Related