Inserting Date Into String
May 5, 2008
Hi again, I am having troubles inserting a datetime value in a table to a string. what iw ant to do is have it be sent in an email. its an attendance email. here is the code i have right now:
select @summaryreport = isnull (@summaryreport + '; ',''+ char(13))+ '<BR>' +'Instructor '+instructor + ' Student ' + Fname + ' ' + Lname + ' - ' + classname +' ' + classdate from #tabledata
i get this as an error
Msg 241, Level 16, State 1, Line 92
Conversion failed when converting datetime from character string.
View 1 Replies
May 4, 2007
Hi,
I have soma ado.net code that inserts 7 parameters in a database ( a date, 6 integers).
I also use a self incrementing ID but the date is set as primary key because for each series of 6 numbers of a certain date there may only be 1 entry. Moreover only 1 entry of 6 integers is possible for 2 days of the week, (tue and fr).
I manage to insert a row of data in the database, where the date is set as smalldatetime and displays as follows: 1/05/2007 0:00:00 in the table.
I want to retrieve the series of numbers for a certain date that has been entered (without taking in account the hours and seconds).
A where clause seems to be needed but I don’t know the syntax or don’t find the right function
I use the following code to insert the row :
command.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime, 40, "LDate"));
command.Parameters[6].Value = DateTime.Today.ToString();
command.ExecuteNonQuery();
and the following code to get the row back (to put in arraylist):
“SELECT C1, C2, C3, C4, C5, C6 FROM Series WHERE (LDate = Today())?
WHERE LDate = '" + DateTime.Today.ToString() + "'"
Which is the correct syntax? Is there a better way to insert and select based on the date?
I don’t get any error messages and the code executes fine but I only get an empty datatable in my dataset (the table isn’t looped for rows I noticed while debugging).
Today’s date is in the database but isn’t found by my tsql code I think.
Any help would be greatly appreciated!
Grtz
Pascal
View 5 Replies
View Related
Feb 19, 2004
Hi SQL Gurus,
I have an XML question to which I am kind of new.
I have an XML string that I get by using a query similar to the following....
SELECT 1 AS Tag,
NULL AS Parent,
NULL AS [Zip_ROOT!1!],
NULL AS [Zip!2!Value!element],
NULL AS [Zip!2!State!element]
FROM ZipCodes
UNION
SELECT 2,
1,
NULL,
Zip,
State
FROM ZipCodes where id < 3
FOR XML EXPLICIT
This returns an XML string, which is very long. I need to take this string and INSERT/UPDATE to a Text column in a table.
Any kind of help in this regard will be grately appreciated.
Regards,
Varma
View 4 Replies
View Related
Jul 1, 2006
Folks, this isn't exactly a 'Getting Started' question, but I couldn't find a more appropriate Application Development forum.
I'm porting an open source PHP application (http://sourceforge.net/projects/gallery) to use SQL Server as a backend. One of Gallery's unit test scripts tests the ability to insert a string containing a NULL character ( ). It's OK if the string is truncated during insertion, just so long as everything before the is there.
The string being inserted looks like:
$testString = "The NULL character should be escaped !";
(Note the between "escaped " and " !")
The error that the Gallery test script is getting is:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'The NULL character should be escaped '.] in EXECUTE("INSERT INTO g2_PluginParameterMap (g_pluginType, g_pluginId, g_itemId, g_parameterName, g_parameterValue) VALUES ('module','unitTestModule',1,'test19476','The NULL character should be escaped !')")
It looks like SQL Server is complaining about the syntax. I've written a much simpler test script in the hopes of reproducing the problem, but I don't know if what I'm now hitting is the same problem or a different one.
My simple script is:
<?php
$localhost = exec("hostname");
$database = "gallery2";
$uid = "g2user";
$pwd = "g2pwd";
$connectString = "Host=PROVIDER=MSDASQL;DRIVER={SQL Server};";
$connectString .= "SERVER=$localhost\sqlexpress;";
$connectString .= "DATABASE=$database;";
$connectString .= "UID=$uid;PWD=$pwd";
$sqlTableDrop = "drop table ljmtemp";
$sqlTableCreate = "create table ljmtemp (col1 nvarchar(100))";
$sqlTableQuery = "select len(col1) from ljmtemp";
// Connect to the db
$db = new COM("ADODB.Connection") or die("Cannot start ADO");
$db->open($connectString);
// Drop & recreate the table
$db->Execute ($sqlTableDrop);
$db->Execute ($sqlTableCreate);
// Insert the test data
//$testString = "The NULL character should be escaped !";
$testString = "This is a test string.";
$res = $db->Execute("insert into ljmtemp (col1) values ('$testString')");
if (!$res) die ("INSERT failed");
// Disconnect from the db
$db->Close();
?>
And it results in:
C:MyServer>php testMsSqlInsertNull.php
PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark after the character string 'The NULL character should be escaped '.' in C:MyServer estMsSqlInsertNull.php:27
Stack trace:
#0 C:MyServer estMsSqlInsertNull.php(27): com->Execute('insert into ljm...')
#1 {main}
thrown in C:MyServer estMsSqlInsertNull.php on line 27
I'm not sure if this is the same problem as Gallery is reporting or another one.
It looks like somebody is treating the as a string terminator, but when i double the backslash the literal '