Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
barnsley
Starting Member
34 Posts |
Posted - 2012-07-31 : 06:45:20
|
Our webiste has several contact forms which all go into the same table.We therefore have to create views to display the results from each webform (separating by fieldID and so on).however, when a user leaves a field blank our fieldID does not record an entry and so the view fails to display the rest of the form.part of the SQL code is below:SELECT TOP 100 PERCENT WebFormData_2.FieldValue AS Surname, WebFormData_7.FieldValue AS SpecialReqFROM db.R INNER JOIN db.WebFormData WebFormData_2 ON db.R.WebFormRowId = WebFormData_2.WebFormRowId INNER JOIN db.WebFormData WebFormData_7 ON db.R.WebFormRowId = WebFormData_7.WebFormRowIdWHERE (WebFormData_2.WebFormFieldId =98) AND (WebFormData_7.WebFormFieldId =99) if we replace =99 with <>99then this results in the form being displayed, but it also displays several times (with duplicate entries in the view).mark. |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-31 : 07:01:18
|
neither =99 nor <>99 will give true null values.I suspect yoou might wantSELECT TOP 100 PERCENT WebFormData_2.FieldValue AS Surname, WebFormData_7.FieldValue AS SpecialReqFROM db.RJOIN db.WebFormData WebFormData_2ON db.R.WebFormRowId = WebFormData_2.WebFormRowIdand WebFormData_2.WebFormFieldId =98left JOIN db.WebFormData WebFormData_7ON db.R.WebFormRowId = WebFormData_7.WebFormRowIdand WebFormData_7.WebFormFieldId =99that will return a row if there is no WebFormData_7.WebFormFieldId =99==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
barnsley
Starting Member
34 Posts |
Posted - 2012-07-31 : 10:54:06
|
thanks nigel,that works a treat!mark. |
|
|
|
|
|