通过避免null连接值并使用下面提到的验证构建插入查询: [英] concatenate values by avoiding null and build insert query with validation mentioned below:

查看:61
本文介绍了通过避免null连接值并使用下面提到的验证构建插入查询:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后端数据库有以下字段:

1. Full_name

2.前缀

3.名字

4.中间名

5.姓氏



前端是一个带有相应文本框字段的表单应用程序。

请不要建议使用full_name的计算列,因为用户可以选择使用eith全名或拆分名称来更新名称。因此,在这种情况下,我不能在我的插入中使用全名,如果它成为计算列,则更新查询。







如果用户只输入全名,则只需要更新db的fullname字段。

如果用户选择输入拆分名,则拆分名在后端随之更新必须使用拆分名称的串联来更新fullname。

串联应该发生,例如prefix_firstname_middlename_lastname;

Ex:



1)prefix = Mr;第一个:Mahesh middle = B,last = kumar

然后输出全名:Mahesh b kumar先生

2)如果这些文件中的任何一个为null,则连接则不应该是任何额外的空间;

例如:IF firstname为null;

然后输出应该是B kumar先生而不是先生[此处还有一个空间] b kumar。





在Windows应用程序表单中单击按钮进行保存后,我将使用以下定义调用savemethod():

Savemethod(以上所有参数都传递给此方法,查询将在建立)。



如何在此方法中使用上述验证构建插入查询。



1.我想知道如何使用c#和sql构建插入查询;

2.如果我正在构建插入在存储过程中查询,我如何使用sql server 2008查询连接这些值;

Backend database has these fields:
1. Full_name
2. Prefix
3. Firstname
4. Middlename
5. Lastname

The front end is a form application with corresponding text box fields.
Here please do not suggest the use of calculated columns for full_name because the user has the option to update the name using eith full name or split names,any one. So in that case i cannot use full name in my insert,update queries if it becomes calculated column.



If the user enter only fullname , then only fullname field of db has to be updated.
If the user opts to enter the splitnames, the the splitnames are updated at the backend along with this the fullname has to be updated with the concatenation of split names.
The concatenation should happen such that prefix_firstname_middlename_lastname;
Ex:

1) prefix=Mr ; first:Mahesh middle=B ,last=kumar
then output fullname: Mr Mahesh b kumar
2) if any of these fileds are null , while concatenating then there should not be any extra space;
for ex: IF firstname is null ;
then the output should be Mr B kumar not Mr [one more space here] b kumar.


Once the button is clicked for save in the windows application form , I’m calling the savemethod () with the below definition:
Savemethod ( all the above params are passed to this method where the query will be built) .

How do I build the insert query with the above validations in this method.

1. I would like to know how to build insert query using both c# and sql ;
2. If I'm building insert query within stored procedure,how do i concatenate these values using sql server 2008 query;

推荐答案

你有什么尝试?

编写存储过程并对其进行测试;然后,如果有问题,请发布您的SQL语句,数据和结果。
And what have you tried to do?
Write a stored procedure and test it; then, if there are issues, post your SQL statement, data and results.


再次,编写一个存储过程并显示它正在做什么/不做什么。人们会帮忙,但我们需要先看看你尝试过的东西。
Again, write a stored procedure and show what is it doing / not doing. People will help, but we need to see what you have tried first.


这篇关于通过避免null连接值并使用下面提到的验证构建插入查询:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆