I am rewriting more code from Access to SQL Server and I have never encountered a TRIM code before, any ideas how to write it for SQL Server as far as I know there is not just plain TRIM for SQL Server
Trim([FCT_TYP_CD]) & " (" & Trim([Dep_TYP_CD]) & ")" AS [Course Owner]
SELECT RTRIM(LTRIM([FCT_TYP_CD])) + ' (' +
RTRIM(LTRIM([Dep_TYP_CD])) + ')' AS [Course Owner]
LTRIM(#String)
RTRIM(#string)
or
LTRIM(RTRIM(#string))
Related
I have a simple gridview which reads data from my SQL server database, and shows it. The data is partly in Hebrew. But when I use the gidview to read the data - I get question marks instead of Hebrew letters... once i checked my database table it also stored as question marks.
What Should I do ? changing the settings of my SQL server or should I change my SQL command statement
Please need help.
I am using Vb 2008 Windows Application C# and SQL server 2014
Code
if (!string.IsNullOrEmpty(txt_C_Request.Text))
{
con = new SqlConnection("Server=" + server + ";Database=" + db + ";User Id=" + user + ";Password=" + pass + "");
SqlCommand Insert_Temp = new SqlCommand("insert into [QAMNI].[dbo].[tbl_Talab_Temp] ([T_ID],[Items_ID],[Car_ID],[Items_Name]) values ('" + txt_T_ID.Text + "','" + txtTempCount.Text + "','" + txt_Car_ID.Text + "','" + txt_C_Request.Text + "')", con);
con.Open();
Insert_Temp.ExecuteNonQuery();
con.Close();
txt_C_Request.Text = "";
Get_Count_Insert_Temp();
Get_Tem_GV();
txt_C_Request.Focus();
}
Thank you
You need to use a data type nvarchar or nchar in order to store Unicode characters. Unicode character literals must also be prefixed with N.
So, instead of
set address = 'כַּף סוֹפִית'
Write to a nvarchar field without the unicode prefix
set address = N'כַּף סוֹפִית'
Take a look at this: N prefix before string in Transact-SQL query
I have been trying to use the MERGE statement in my Access application. When I use the following code (simplified for readability):
dim strSqlMerge as string
strSqlMerge = "MERGE TargeTable AS T USING SourceTable as S " & _
" ON T.PrimaryKeyColumn = S.PrimaryKeyColumn " & _
" WHEN MATCHED AND PrimaryKeyColumn = 'hardcodedvalue' THEN " & _
" UPDATE SET T.Column1 = S.Column1, T.Column2 = S.Column2, ..."
Currentdb.Execute strSqlMerge
I get the error 3078: The Microsoft Office Access database engine cannot find the input table or query 'MERGE TargeTable AS T USING SourceTable as S ...'
Make sure it exists and that its name is spelled correctly.
Help will be appreciated.
Access does not support MERGE. That construct exists in T-SQL (SQL Server) and other SQL dialects, but not in Access SQL.
I have a script which is running perfectly in local host. the code is this
string sql = "insert into Usertable ";
sql += "values(" + mVendid + ", '" + usrname + "','" + usrpass + "', CONVERT(datetime, " + datecreation + ", 103)" + "," + createdby + ")";
The values are (1,'sa','ee','05/18/2013', 1)
This is also running fine if I run the same in sql server. But I am having only problem when I am inserting the date field. If I remove teh date field in insert statement the code is running absolutely fine
But while running the same in webserver it is encountering an error as
Server Error in '/' Application.
Divide by zero error encountered.
The statement has been terminated.
Using code 103 with CONVERT means that you're suppling as input a date in the format dd/mm/yy while in your code you are using mm/dd/yy format.
You could try with these values:
(1,'sa','ee','18/05/2013', 1)
For further reference about convert function check this out
I want to automate some Mail Merge functionality using data drawn from a SQL Server Database. Here’s the code I’m using:
Sub open_DSN()
Dim strConnection As String
ActiveDocument.MailMerge.CreateDataSource Name:="DB-NAME", _
Connection:="Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=DB-NAME;Data Source=DATA-SOURCE", _
SQLStatement:="select * from DataTable"
ActiveDocument.MailMerge.OpenDataSource Name:="DB-NAME"
If ActiveDocument.MailMerge.DataSource.Name <> "" Then _
MsgBox ActiveDocument.MailMerge.DataSource.Name
' – code lifted from MS Help within Word that seems the nearest to what I require
'With ActiveDocument.MailMerge
' .MainDocumentType = wdFormLetters
' strConnection = "DSN=MS Access Databases;" _
' & "DBQ=C:\Northwind.mdb;" _
' & "FIL=RedISAM;"
' .OpenDataSource Name:="C:\NorthWind.mdb", _
' Connection:=strConnection, _
' SQLStatement:="SELECT * FROM Customers"
'End With
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
strConnection = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=DB-NAME;Data Source=DATA-SOURCE"
.OpenDataSource Name:="DB-NAME", _
Connection:=strConnection, _
SQLStatement:="SELECT * FROM DataTable"
End With
End Sub
Unfortunately I can’t get this code to display the data. What am I doing wrong?
Did you replace "DB-NAME" and "DATA-SOURCE" with the actual values in the connection string?
So do you have a sql server instance called DATA-Source with a Database called DB-Name?
Probably not?
More Like MyServer\MyInstance and MyDatabase
I don't know MailMerge, so I can't comment on the code that you use to establish the connection.
But if you are sure that the code is okay, then it's probably the connection string.
There are lots of different possible connection strings to connect to SQL Server, so the right solution depends on your SQL Server version and setup (for example, Windows authentification or SQL Server authentification...).
This MSDN article which says that MailMerge supports OLE DB and ODBC, so you can use either of these.
If you tell us more about your SQL Server setup, we can help you find the correct connection string for your use case.
Using vbscript to process a form in classic ASP, I create the following insert statement:
INSERT INTO [RemitChangeControl].[dbo].[FormData]
VALUES
(142, 2, 'asdfasdf');
I get this error:
Microsoft SQL Server Native Client 10.0 error '80040e14'
Incorrect syntax near '<'.
This strange because no where in my insert statement is the character '<' found. So how could there be an error near a non-existent character?
Oddly enough, if I create the same statement by including it directly in my code as a literal string, it works correctly.
Here's a quick tutorial on setting up a trace using SQL Server Management Studio and Profiler:
http://www.petri.co.il/monitoring-with-sql-profiler.htm
Code I used for debugging another issue caused my problem. Specifically, I misunderstood VBScript parameter passing and assignment semantics.
Here's the code that runs the insert statement:
insert_statement = INSERT INTO [RemitChangeControl].[dbo].[FormData]" & vbcrlf _
& "VALUES " & vbcrlf _
& join(value_clauses.Items, "," & vbcrlf) & ";"
write_to_web_page insert_statement ' OOPS!
objconn.Execute insert_statement
Here's the function that it was calling:
sub write_to_web_page(s)
' assigment to s mutates it!
s = Replace(Server.HTMLEncode(s), vbcrlf, "<br />")
response.write("<p>" & t & "</p>")
end sub
When I pass insert_statement to write_to_web_page it is passed by reference. When I reassign the result of Replace to the local variable it mutates in the caller, resulting in insert_statment containing a number of "<br />". That's what I get for expecting Python assignment semantics in VBScript.
I finally figured this out while chopping my code down to size to flesh out my question here. Suprisingly, my small example did not exhibit the bug. I then inserted calls to write_to_web_page to figure out what was going on. Then my bug reappeared and the light bulb went on.